Flake template for NixOS, nix-darwin, and Home Manager. Uses purr for directory discovery and cattery-modules for system and user modules.
Part of develop-templates.
Initialize from the flake template:
nix flake init -t "github:nixcafe/develop-templates#nix-config" --refreshOr add the registry alias once (already set on hosts using cattery-modules):
nix registry add beans "github:nixcafe/develop-templates"
nix flake init -t beans#nix-configOr create a repository on GitHub:
gh repo create my-nixos-config --template nixcafe-develop/nix-config --cloneEnter the shell and inspect outputs:
direnv allow
# or: nix develop
nix flake show- Edit
lib/host/default.nixwith your username, name, email, timezone, default login shell, and SSH authorized keys. Starship settings live inlib/host/config/starship.toml. - Generate
hardware.nixwithnixos-generate-config --show-hardware-config > systems/<arch-format>/<name>/hardware.nixand import./hardware.nixfrom the host'sdefault.nix. Bothhostname-nixosandhostname-servership withlib.mkDefaultplaceholders forfileSystems."/"(andboot.loader.grub.deviceonhostname-server) so the flake evaluates cleanly before real hardware config is added. - Secrets are disabled by default in
lib/secrets/default.nix. Pointmy-secretsinflake.nixat your own repository and setenable = truewhen ready.
Systems under systems/:
x86_64-linux/hostname-nixos: NixOS desktop with KDE Plasma and dev room.x86_64-linux/hostname-server: NixOS server with root user and IP forwarding.x86_64-linux/hostname-wsl: NixOS-WSL host using the defaultnixosuser (NixOS-WSL requires a non-rootdefaultUser).aarch64-darwin/hostname-mbp: macOS host using nix-darwin.x86_64-linux/{graphical,minimal,minimal-no-zfs}: ISO installer image recipes declared withimages = [ "iso-installer" ]inmeta.nix. Image-only hosts appear underimagesand are omitted fromnixosConfigurationsunlessdeployable = trueis set inmeta.nix.
Homes under homes/<arch-format>/<user>@<host>/ are exposed as standalone homeConfigurations and linked into the matching host automatically.
Add a NixOS host by creating systems/<arch-format>/<name>/default.nix:
{
imports = [ ./hardware.nix ];
cattery.room.desktop.dev.enable = true;
system.stateVersion = "25.11";
}For a nix-darwin host, create systems/aarch64-darwin/<name>/default.nix without hardware.nix and use an integer system.stateVersion (such as 5). purr sets networking.hostName from the directory name. Put optional host metadata in a sibling meta.nix.
Add a home by creating homes/<arch-format>/<user>@<host>/default.nix:
{
cattery.room.desktop.dev.enable = true;
}purr sets home.username and home.homeDirectory from the directory name, and modules/home/home/default.nix sets the default home.stateVersion.
Add an image recipe by setting images in systems/<arch-format>/<name>/meta.nix:
{
images = [ "iso-installer" ];
}Build it with:
nix build .#images.graphical.iso-installer.
├── flake.nix
├── checks/git-hooks/default.nix # nixfmt, deadnix, statix hooks
├── shells/default/default.nix # dev shell with git hooks
├── systems/
│ ├── aarch64-darwin/hostname-mbp/
│ └── x86_64-linux/
│ ├── graphical/
│ ├── hostname-nixos/
│ ├── hostname-server/
│ ├── hostname-wsl/
│ ├── minimal/
│ └── minimal-no-zfs/
├── homes/
│ ├── aarch64-darwin/nixos@hostname-mbp/
│ └── x86_64-linux/
│ ├── nixos@graphical/
│ ├── nixos@hostname-nixos/
│ ├── nixos@hostname-wsl/
│ ├── nixos@minimal/
│ ├── nixos@minimal-no-zfs/
│ └── root@hostname-server/
├── modules/
│ ├── darwin/{brew,user}/
│ ├── home/{home,secrets,user}/
│ ├── nixos/user/
│ └── shared/secrets/
├── lib/
│ ├── host/
│ ├── module/
│ └── secrets/
└── statix.toml
nix develop
nix flake show
nix flake check
nix fmt
pre-commit run --all-files
nix build .#nixosConfigurations.hostname-nixos.config.system.build.toplevel
nix build .#images.graphical.iso-installer
sudo nixos-rebuild switch --flake .#hostname-nixos