optimize flake shape and add devshell

This commit is contained in:
Harivansh Rathi 2026-03-29 23:00:59 -04:00
parent f3d61787f0
commit 6dfef30594
8 changed files with 202 additions and 121 deletions

View file

@ -38,13 +38,22 @@ 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) 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
View file

@ -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",

101
flake.nix
View file

@ -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,52 +44,63 @@
}; };
}; };
outputs = inputs @ { outputs =
inputs@{
self, self,
flake-parts,
nixpkgs, nixpkgs,
nix-darwin, nix-darwin,
home-manager, home-manager,
claudeCode,
nix-homebrew, nix-homebrew,
... ...
}: let }:
darwinSystem = "aarch64-darwin"; let
linuxSystem = "x86_64-linux";
username = "rathi"; username = "rathi";
darwinConfigName = "darwin"; hosts = import ./lib/hosts.nix { inherit username; };
darwinMachineHostname = "hari-macbook-pro";
linuxConfigName = "netty"; mkPkgs =
linuxHostname = "netty"; system:
darwinPkgs = import nixpkgs {system = darwinSystem;}; import nixpkgs {
linuxPkgs = import nixpkgs { inherit system;
system = linuxSystem;
config.allowUnfree = true; config.allowUnfree = true;
}; };
in {
formatter.${darwinSystem} = darwinPkgs.alejandra;
formatter.${linuxSystem} = linuxPkgs.alejandra;
darwinConfigurations.${darwinConfigName} = nix-darwin.lib.darwinSystem { mkHomeManagerModule =
system = darwinSystem; host:
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.useGlobalPkgs = true;
home-manager.useUserPackages = true; home-manager.useUserPackages = true;
home-manager.extraSpecialArgs = { home-manager.extraSpecialArgs = {
inherit inputs self username; inherit inputs self username;
hostname = darwinMachineHostname; hostname = host.hostname;
}; };
home-manager.backupFileExtension = "hm-bak"; home-manager.backupFileExtension = "hm-bak";
home-manager.users.${username} = import ./home; home-manager.users.${username} = import host.homeModule;
};
in
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
hosts.darwin.system
hosts.netty.system
];
imports = [
./modules/devshells.nix
];
flake = {
darwinConfigurations.${hosts.darwin.name} = nix-darwin.lib.darwinSystem {
system = hosts.darwin.system;
specialArgs = {
inherit inputs self username;
hostname = hosts.darwin.hostname;
};
modules = [
./hosts/${hosts.darwin.name}
home-manager.darwinModules.home-manager
nix-homebrew.darwinModules.nix-homebrew
{
users.users.${username}.home = hosts.darwin.homeDirectory;
nix-homebrew = { nix-homebrew = {
enable = true; enable = true;
@ -98,42 +109,34 @@
autoMigrate = true; autoMigrate = true;
}; };
} }
(mkHomeManagerModule hosts.darwin)
]; ];
}; };
nixosConfigurations.${linuxConfigName} = nixpkgs.lib.nixosSystem { nixosConfigurations.${hosts.netty.name} = nixpkgs.lib.nixosSystem {
system = linuxSystem; system = hosts.netty.system;
specialArgs = { specialArgs = {
inherit inputs self username; inherit inputs self username;
hostname = linuxHostname; hostname = hosts.netty.hostname;
}; };
modules = [ modules = [
inputs.disko.nixosModules.disko inputs.disko.nixosModules.disko
./hosts/${linuxConfigName}/configuration.nix ./hosts/${hosts.netty.name}/configuration.nix
home-manager.nixosModules.home-manager home-manager.nixosModules.home-manager
{ (mkHomeManagerModule hosts.netty)
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.${hosts.netty.name} = home-manager.lib.homeManagerConfiguration {
homeConfigurations.${linuxConfigName} = home-manager.lib.homeManagerConfiguration { pkgs = mkPkgs hosts.netty.system;
pkgs = linuxPkgs;
extraSpecialArgs = { extraSpecialArgs = {
inherit inputs self username; inherit inputs self username;
hostname = linuxConfigName; hostname = hosts.netty.hostname;
}; };
modules = [ modules = [
./hosts/${linuxConfigName} hosts.netty.standaloneHomeModule
]; ];
}; };
}; };
};
} }

View file

@ -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 = {

View file

@ -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];
environment.variables = {
EDITOR = "nvim";
VISUAL = "nvim";
};
nix.settings = {
auto-optimise-store = true;
experimental-features = [
"nix-command"
"flakes"
];
trusted-users = [
"root" "root"
username username
]; ];
};
nix.gc = { environment.systemPackages = packageSets.extras ++ [
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
]; ];

21
lib/hosts.nix Normal file
View 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}";
};
}

View file

@ -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; automatic = true;
options = "--delete-older-than 14d";
}
// (
if pkgs.stdenv.isDarwin then
{
interval = { interval = {
Weekday = 7; Weekday = 7;
Hour = 3; Hour = 3;
Minute = 0; Minute = 0;
}; };
options = "--delete-older-than 14d"; }
}; else
{
dates = "weekly";
}
);
nixpkgs.config.allowUnfree = true; nixpkgs.config.allowUnfree = true;

23
modules/devshells.nix Normal file
View 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
];
};
};
}