mirror of
https://github.com/harivansh-afk/nix.git
synced 2026-04-15 09:01:16 +00:00
commit
d088a98954
13 changed files with 268 additions and 133 deletions
19
README.md
19
README.md
|
|
@ -38,13 +38,24 @@ just secrets-sync # shell env vars -> ~/.config/secrets/shell.zsh
|
||||||
just secrets-restore-files # SSH keys, AWS, GCloud, Codex, GitHub CLI
|
just secrets-restore-files # SSH keys, AWS, GCloud, Codex, GitHub CLI
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## dev
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nix develop
|
||||||
|
just check
|
||||||
|
just fmt
|
||||||
|
```
|
||||||
|
|
||||||
## layout
|
## layout
|
||||||
|
|
||||||
```
|
```
|
||||||
hosts/darwin/ - macOS nix-darwin config
|
hosts/darwin/ - macOS host entrypoint
|
||||||
hosts/netty/ - NixOS VPS config (disko + hardware)
|
hosts/netty/ - NixOS VPS entrypoint (disko + hardware)
|
||||||
modules/ - system-level modules (packages, macos defaults, homebrew)
|
modules/ - shared system modules + devshells
|
||||||
home/ - Home Manager modules (shell, editor, tools)
|
modules/hosts/ - flake-parts host output definitions
|
||||||
|
modules/nixpkgs.nix - shared flake context (hosts, args, pkgs helpers)
|
||||||
|
home/ - Home Manager modules
|
||||||
|
lib/hosts.nix - host metadata used by the flake
|
||||||
lib/ - shared package sets and theme system
|
lib/ - shared package sets and theme system
|
||||||
config/ - repo-owned config files (nvim, tmux, etc.)
|
config/ - repo-owned config files (nvim, tmux, etc.)
|
||||||
scripts/ - secret management and utility scripts
|
scripts/ - secret management and utility scripts
|
||||||
|
|
|
||||||
34
flake.lock
generated
34
flake.lock
generated
|
|
@ -76,6 +76,24 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"flake-parts": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs-lib": "nixpkgs-lib"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1772408722,
|
||||||
|
"narHash": "sha256-rHuJtdcOjK7rAHpHphUb1iCvgkU3GpfvicLMwwnfMT0=",
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"rev": "f20dc5d9b8027381c474144ecabc9034d6a839a3",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"flake-utils": {
|
"flake-utils": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"systems": "systems"
|
"systems": "systems"
|
||||||
|
|
@ -226,6 +244,21 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"nixpkgs-lib": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1772328832,
|
||||||
|
"narHash": "sha256-e+/T/pmEkLP6BHhYjx6GmwP5ivonQQn0bJdH9YrRB+Q=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nixpkgs.lib",
|
||||||
|
"rev": "c185c7a5e5dd8f9add5b2f8ebeff00888b070742",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nixpkgs.lib",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"nixpkgs_2": {
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1767640445,
|
"lastModified": 1767640445,
|
||||||
|
|
@ -265,6 +298,7 @@
|
||||||
"agentcomputer-cli": "agentcomputer-cli",
|
"agentcomputer-cli": "agentcomputer-cli",
|
||||||
"claudeCode": "claudeCode",
|
"claudeCode": "claudeCode",
|
||||||
"disko": "disko",
|
"disko": "disko",
|
||||||
|
"flake-parts": "flake-parts",
|
||||||
"googleworkspace-cli": "googleworkspace-cli",
|
"googleworkspace-cli": "googleworkspace-cli",
|
||||||
"home-manager": "home-manager",
|
"home-manager": "home-manager",
|
||||||
"nix-darwin": "nix-darwin",
|
"nix-darwin": "nix-darwin",
|
||||||
|
|
|
||||||
100
flake.nix
100
flake.nix
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||||
|
|
||||||
nix-darwin = {
|
nix-darwin = {
|
||||||
url = "github:nix-darwin/nix-darwin/master";
|
url = "github:nix-darwin/nix-darwin/master";
|
||||||
|
|
@ -24,7 +25,6 @@
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
agentcomputer-cli = {
|
agentcomputer-cli = {
|
||||||
url = "path:/Users/rathi/Documents/GitHub/companion/agentcomputer/apps/cli";
|
url = "path:/Users/rathi/Documents/GitHub/companion/agentcomputer/apps/cli";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|
@ -44,96 +44,14 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = inputs @ {
|
outputs =
|
||||||
self,
|
inputs@{ flake-parts, ... }:
|
||||||
nixpkgs,
|
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||||
nix-darwin,
|
imports = [
|
||||||
home-manager,
|
./modules/nixpkgs.nix
|
||||||
claudeCode,
|
./modules/devshells.nix
|
||||||
nix-homebrew,
|
./modules/hosts/darwin.nix
|
||||||
...
|
./modules/hosts/netty.nix
|
||||||
}: let
|
|
||||||
darwinSystem = "aarch64-darwin";
|
|
||||||
linuxSystem = "x86_64-linux";
|
|
||||||
username = "rathi";
|
|
||||||
darwinConfigName = "darwin";
|
|
||||||
darwinMachineHostname = "hari-macbook-pro";
|
|
||||||
linuxConfigName = "netty";
|
|
||||||
linuxHostname = "netty";
|
|
||||||
darwinPkgs = import nixpkgs {system = darwinSystem;};
|
|
||||||
linuxPkgs = import nixpkgs {
|
|
||||||
system = linuxSystem;
|
|
||||||
config.allowUnfree = true;
|
|
||||||
};
|
|
||||||
in {
|
|
||||||
formatter.${darwinSystem} = darwinPkgs.alejandra;
|
|
||||||
formatter.${linuxSystem} = linuxPkgs.alejandra;
|
|
||||||
|
|
||||||
darwinConfigurations.${darwinConfigName} = nix-darwin.lib.darwinSystem {
|
|
||||||
system = darwinSystem;
|
|
||||||
specialArgs = {
|
|
||||||
inherit inputs self username;
|
|
||||||
hostname = darwinMachineHostname;
|
|
||||||
};
|
|
||||||
modules = [
|
|
||||||
./hosts/${darwinConfigName}
|
|
||||||
home-manager.darwinModules.home-manager
|
|
||||||
nix-homebrew.darwinModules.nix-homebrew
|
|
||||||
{
|
|
||||||
users.users.${username}.home = "/Users/${username}";
|
|
||||||
|
|
||||||
home-manager.useGlobalPkgs = true;
|
|
||||||
home-manager.useUserPackages = true;
|
|
||||||
home-manager.extraSpecialArgs = {
|
|
||||||
inherit inputs self username;
|
|
||||||
hostname = darwinMachineHostname;
|
|
||||||
};
|
|
||||||
home-manager.backupFileExtension = "hm-bak";
|
|
||||||
home-manager.users.${username} = import ./home;
|
|
||||||
|
|
||||||
nix-homebrew = {
|
|
||||||
enable = true;
|
|
||||||
enableRosetta = true;
|
|
||||||
user = username;
|
|
||||||
autoMigrate = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
nixosConfigurations.${linuxConfigName} = nixpkgs.lib.nixosSystem {
|
|
||||||
system = linuxSystem;
|
|
||||||
specialArgs = {
|
|
||||||
inherit inputs self username;
|
|
||||||
hostname = linuxHostname;
|
|
||||||
};
|
|
||||||
modules = [
|
|
||||||
inputs.disko.nixosModules.disko
|
|
||||||
./hosts/${linuxConfigName}/configuration.nix
|
|
||||||
home-manager.nixosModules.home-manager
|
|
||||||
{
|
|
||||||
home-manager.useGlobalPkgs = true;
|
|
||||||
home-manager.useUserPackages = true;
|
|
||||||
home-manager.extraSpecialArgs = {
|
|
||||||
inherit inputs self username;
|
|
||||||
hostname = linuxHostname;
|
|
||||||
};
|
|
||||||
home-manager.backupFileExtension = "hm-bak";
|
|
||||||
home-manager.users.${username} = import ./home/netty.nix;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
# Standalone Home Manager config (fallback for non-NixOS Linux)
|
|
||||||
homeConfigurations.${linuxConfigName} = home-manager.lib.homeManagerConfiguration {
|
|
||||||
pkgs = linuxPkgs;
|
|
||||||
extraSpecialArgs = {
|
|
||||||
inherit inputs self username;
|
|
||||||
hostname = linuxConfigName;
|
|
||||||
};
|
|
||||||
modules = [
|
|
||||||
./hosts/${linuxConfigName}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
programs.git = {
|
programs.git = {
|
||||||
enable = true;
|
enable = true;
|
||||||
lfs.enable = true;
|
lfs.enable = true;
|
||||||
|
signing.format = "openpgp";
|
||||||
|
|
||||||
settings = {
|
settings = {
|
||||||
user = {
|
user = {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ in {
|
||||||
imports = [
|
imports = [
|
||||||
./hardware-configuration.nix
|
./hardware-configuration.nix
|
||||||
./disk-config.nix
|
./disk-config.nix
|
||||||
|
../../modules/base.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
boot.loader.grub = {
|
boot.loader.grub = {
|
||||||
|
|
@ -52,35 +53,12 @@ in {
|
||||||
|
|
||||||
security.sudo.wheelNeedsPassword = false;
|
security.sudo.wheelNeedsPassword = false;
|
||||||
|
|
||||||
programs.zsh.enable = true;
|
nix.settings.trusted-users = lib.mkForce [
|
||||||
environment.shells = [pkgs.zsh];
|
"root"
|
||||||
|
username
|
||||||
|
];
|
||||||
|
|
||||||
environment.variables = {
|
environment.systemPackages = packageSets.extras ++ [
|
||||||
EDITOR = "nvim";
|
|
||||||
VISUAL = "nvim";
|
|
||||||
};
|
|
||||||
|
|
||||||
nix.settings = {
|
|
||||||
auto-optimise-store = true;
|
|
||||||
experimental-features = [
|
|
||||||
"nix-command"
|
|
||||||
"flakes"
|
|
||||||
];
|
|
||||||
trusted-users = [
|
|
||||||
"root"
|
|
||||||
username
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
nix.gc = {
|
|
||||||
automatic = true;
|
|
||||||
dates = "weekly";
|
|
||||||
options = "--delete-older-than 14d";
|
|
||||||
};
|
|
||||||
|
|
||||||
nixpkgs.config.allowUnfree = true;
|
|
||||||
|
|
||||||
environment.systemPackages = packageSets.core ++ packageSets.extras ++ [
|
|
||||||
pkgs.bubblewrap
|
pkgs.bubblewrap
|
||||||
pkgs.pnpm
|
pkgs.pnpm
|
||||||
];
|
];
|
||||||
|
|
|
||||||
3
justfile
3
justfile
|
|
@ -17,7 +17,8 @@ switch config='darwin':
|
||||||
if [[ "{{config}}" == "darwin" ]]; then
|
if [[ "{{config}}" == "darwin" ]]; then
|
||||||
sudo env PATH="$PATH" nix --extra-experimental-features 'nix-command flakes' run github:nix-darwin/nix-darwin/master#darwin-rebuild -- switch --flake path:.#{{config}}
|
sudo env PATH="$PATH" nix --extra-experimental-features 'nix-command flakes' run github:nix-darwin/nix-darwin/master#darwin-rebuild -- switch --flake path:.#{{config}}
|
||||||
else
|
else
|
||||||
nix --extra-experimental-features 'nix-command flakes' run github:nix-community/home-manager -- switch --flake path:.#{{config}} -b hm-bak
|
backup_ext="hm-bak-$(date +%Y%m%d-%H%M%S)"
|
||||||
|
nix --extra-experimental-features 'nix-command flakes' run github:nix-community/home-manager -- switch --flake path:.#{{config}} -b "$backup_ext"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
|
|
|
||||||
21
lib/hosts.nix
Normal file
21
lib/hosts.nix
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
{ username }:
|
||||||
|
{
|
||||||
|
darwin = {
|
||||||
|
name = "darwin";
|
||||||
|
kind = "darwin";
|
||||||
|
system = "aarch64-darwin";
|
||||||
|
hostname = "hari-macbook-pro";
|
||||||
|
homeModule = ../home;
|
||||||
|
homeDirectory = "/Users/${username}";
|
||||||
|
};
|
||||||
|
|
||||||
|
netty = {
|
||||||
|
name = "netty";
|
||||||
|
kind = "nixos";
|
||||||
|
system = "x86_64-linux";
|
||||||
|
hostname = "netty";
|
||||||
|
homeModule = ../home/netty.nix;
|
||||||
|
standaloneHomeModule = ../hosts/netty;
|
||||||
|
homeDirectory = "/home/${username}";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ in {
|
||||||
nix.enable = true;
|
nix.enable = true;
|
||||||
|
|
||||||
nix.settings = {
|
nix.settings = {
|
||||||
|
auto-optimise-store = true;
|
||||||
experimental-features = [
|
experimental-features = [
|
||||||
"nix-command"
|
"nix-command"
|
||||||
"flakes"
|
"flakes"
|
||||||
|
|
@ -18,17 +19,28 @@ in {
|
||||||
"@admin"
|
"@admin"
|
||||||
username
|
username
|
||||||
];
|
];
|
||||||
|
use-xdg-base-directories = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
nix.gc = {
|
nix.gc =
|
||||||
automatic = true;
|
{
|
||||||
interval = {
|
automatic = true;
|
||||||
Weekday = 7;
|
options = "--delete-older-than 14d";
|
||||||
Hour = 3;
|
}
|
||||||
Minute = 0;
|
// (
|
||||||
};
|
if pkgs.stdenv.isDarwin then
|
||||||
options = "--delete-older-than 14d";
|
{
|
||||||
};
|
interval = {
|
||||||
|
Weekday = 7;
|
||||||
|
Hour = 3;
|
||||||
|
Minute = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dates = "weekly";
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
nixpkgs.config.allowUnfree = true;
|
nixpkgs.config.allowUnfree = true;
|
||||||
|
|
||||||
|
|
|
||||||
23
modules/devshells.nix
Normal file
23
modules/devshells.nix
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
{ ... }:
|
||||||
|
{
|
||||||
|
perSystem =
|
||||||
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
formatter = pkgs.nixfmt-tree;
|
||||||
|
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
packages = with pkgs; [
|
||||||
|
deadnix
|
||||||
|
git
|
||||||
|
just
|
||||||
|
nixfmt-tree
|
||||||
|
nodePackages.prettier
|
||||||
|
pre-commit
|
||||||
|
selene
|
||||||
|
shfmt
|
||||||
|
statix
|
||||||
|
stylua
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
33
modules/hosts/darwin.nix
Normal file
33
modules/hosts/darwin.nix
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
hosts,
|
||||||
|
inputs,
|
||||||
|
username,
|
||||||
|
mkSpecialArgs,
|
||||||
|
mkHomeManagerModule,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
host = hosts.darwin;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
flake.darwinConfigurations.${host.name} = inputs.nix-darwin.lib.darwinSystem {
|
||||||
|
system = host.system;
|
||||||
|
specialArgs = mkSpecialArgs host;
|
||||||
|
modules = [
|
||||||
|
../../hosts/${host.name}
|
||||||
|
inputs.home-manager.darwinModules.home-manager
|
||||||
|
inputs.nix-homebrew.darwinModules.nix-homebrew
|
||||||
|
{
|
||||||
|
users.users.${username}.home = host.homeDirectory;
|
||||||
|
|
||||||
|
nix-homebrew = {
|
||||||
|
enable = true;
|
||||||
|
enableRosetta = true;
|
||||||
|
user = username;
|
||||||
|
autoMigrate = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
(mkHomeManagerModule host)
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
33
modules/hosts/netty.nix
Normal file
33
modules/hosts/netty.nix
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
hosts,
|
||||||
|
inputs,
|
||||||
|
mkPkgs,
|
||||||
|
mkSpecialArgs,
|
||||||
|
mkHomeManagerModule,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
host = hosts.netty;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
flake = {
|
||||||
|
nixosConfigurations.${host.name} = inputs.nixpkgs.lib.nixosSystem {
|
||||||
|
system = host.system;
|
||||||
|
specialArgs = mkSpecialArgs host;
|
||||||
|
modules = [
|
||||||
|
inputs.disko.nixosModules.disko
|
||||||
|
../../hosts/${host.name}/configuration.nix
|
||||||
|
inputs.home-manager.nixosModules.home-manager
|
||||||
|
(mkHomeManagerModule host)
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
homeConfigurations.${host.name} = inputs.home-manager.lib.homeManagerConfiguration {
|
||||||
|
pkgs = mkPkgs host.system;
|
||||||
|
extraSpecialArgs = mkSpecialArgs host;
|
||||||
|
modules = [
|
||||||
|
host.standaloneHomeModule
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
45
modules/nixpkgs.nix
Normal file
45
modules/nixpkgs.nix
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
{
|
||||||
|
self,
|
||||||
|
inputs,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
username = "rathi";
|
||||||
|
hosts = import ../lib/hosts.nix { inherit username; };
|
||||||
|
|
||||||
|
mkPkgs =
|
||||||
|
system:
|
||||||
|
import inputs.nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
config.allowUnfree = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
mkSpecialArgs = host: {
|
||||||
|
inherit inputs self username;
|
||||||
|
hostname = host.hostname;
|
||||||
|
};
|
||||||
|
|
||||||
|
mkHomeManagerModule =
|
||||||
|
host:
|
||||||
|
{
|
||||||
|
home-manager.useGlobalPkgs = true;
|
||||||
|
home-manager.useUserPackages = true;
|
||||||
|
home-manager.extraSpecialArgs = mkSpecialArgs host;
|
||||||
|
home-manager.backupCommand = "bash ${../scripts/home-manager-backup.sh}";
|
||||||
|
home-manager.users.${username} = import host.homeModule;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
systems = lib.unique (map (host: host.system) (builtins.attrValues hosts));
|
||||||
|
|
||||||
|
_module.args = {
|
||||||
|
inherit
|
||||||
|
username
|
||||||
|
hosts
|
||||||
|
mkPkgs
|
||||||
|
mkSpecialArgs
|
||||||
|
mkHomeManagerModule
|
||||||
|
;
|
||||||
|
};
|
||||||
|
}
|
||||||
25
scripts/home-manager-backup.sh
Normal file
25
scripts/home-manager-backup.sh
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
if [[ $# -eq 0 ]]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
target_path="${1:?expected target path}"
|
||||||
|
base_backup="${target_path}.hm-bak"
|
||||||
|
|
||||||
|
if [[ ! -e "$base_backup" ]]; then
|
||||||
|
mv "$target_path" "$base_backup"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
timestamp="$(date +%Y%m%d-%H%M%S)"
|
||||||
|
backup_path="${base_backup}.${timestamp}"
|
||||||
|
suffix=0
|
||||||
|
|
||||||
|
while [[ -e "$backup_path" ]]; do
|
||||||
|
suffix=$((suffix + 1))
|
||||||
|
backup_path="${base_backup}.${timestamp}.${suffix}"
|
||||||
|
done
|
||||||
|
|
||||||
|
mv "$target_path" "$backup_path"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue