mirror of
https://github.com/smg1024/nix-darwin.git
synced 2026-09-19 05:31:43 +09:00
Poby's nix-darwin setup
- Nix 84.8%
- Lua 13.3%
- Just 1.9%
| .codex | ||
| dotfiles | ||
| hosts | ||
| modules | ||
| secrets | ||
| .gitignore | ||
| .luarc.json | ||
| .sops.yaml | ||
| AGENTS.md | ||
| flake.lock | ||
| flake.nix | ||
| Justfile | ||
| README-ko.md | ||
| README.md | ||
nix-darwin
This repository manages macOS with nix-darwin, home-manager,
nix-homebrew, and sops-nix. It combines small aspect modules into
host-specific configurations and runs Home Manager inside nix-darwin.
What this repo manages
- Flake setup and host configuration in
modules/flake/ - Darwin and Home Manager aspects loaded from
modules/aspects/ - Host declarations loaded from
hosts/ - SOPS-encrypted files in
secrets/, with rules in.sops.yaml - Editor, browser, terminal, shell, desktop, SSH, and CLI configuration for
user
poby
Prerequisites
- macOS on Apple Silicon (
aarch64-darwin) - Nix with flakes enabled (
nix-command+flakes) justfor running repository commandsnhfor the switch, update, debug, and cleanup commands- A SOPS age key at:
$HOME/.config/sops/age/keys.txt
Repository layout
flake.nix:flake-partsentrypoint and flake inputsJustfile: repository commands (dry-run,switch,update,debug,fmt,up,upp,repl,history,clean,gcroot)modules/flake/: repository options, Darwin configuration assembly, and shared context modulesmodules/aspects/: public aspect entry modules such asbase,homebrew,shell,browser,discord,editor, anddesktopmodules/aspects/_*/: private implementation trees imported by their public aspect modulesmodules/aspects/_hammerspoon/: Hammerspoon configuration linked to$HOME/.hammerspoonmodules/aspects/_editor/: NVF and Zed configurationmodules/aspects/_browser/: Zen Browser policies, profile settings, extensions, containers, spaces, and pinned tabsmodules/aspects/_secrets/:sops-nixdeclarations, age key setup, and the Home ManagerSOPS_AGE_KEY_FILEsession variablehosts/: host declarations with asystemvalue and a flatfeatureslistdotfiles/: exported application settings that Nix modules do not loadsecrets/: encrypted files grouped by purpose (github.yaml,ssh.yaml)
Common commands
# List available tasks
just
# Build and switch the configuration for the current hostname
just switch $(hostname)
# Build and switch with detailed logs
just debug $(hostname)
# Evaluate dependencies without building them
just dry-run fenrir
# Format Nix files from the repository root
just fmt .
# Update every flake input and switch
just update fenrir
# Update one flake input and switch
just update fenrir nixpkgs
# Update every flake input without switching
just up
# Update one flake input without switching
just upp nixpkgs
# Build without switching (example host: fenrir)
nix build .#darwinConfigurations.fenrir.system \
--accept-flake-config \
--extra-experimental-features 'nix-command flakes'
# Run the dry-run directly with Nix
nix build .#darwinConfigurations.fenrir.system \
--dry-run \
--accept-flake-config \
--extra-experimental-features 'nix-command flakes'
# Inspect the system profile history
just history
# Remove old generations and unused store paths
just clean
# Inspect automatic GC roots
just gcroot
Configuration notes
flake.nixusesflake-partsand imports./modules/flakedirectly.import-treeloads./modules/aspectsand./hosts.hosts/fenrir.nixandhosts/huginn.nixdefine the available macOS hosts, each with one flat feature list.modules/flake/darwin-configurations.nixcreates eachdarwinConfigurations.<host>output and adds Home Manager for userpoby.modules/aspects/defines the features a host can select:base,nix-core,system-packages,homebrew,macos-defaults,activation,fonts,sudo-auth,shell,cli-tools,git,ssh,secrets,terminal,hammerspoon,editor,browser,discord,desktop,fenrir, andhuginn.- The
cli-toolsaspect configures CLI tools for the user, includingmarp-cliandzoxide. - The
editoraspect imports NVF and Zed. Home Manager manages Zed but leaves user settings, keymaps, tasks, and debug configuration mutable. Zed uses thenixextension. Its Nix language server isnixd, and its formatter is Alejandra. - The
browseraspect manages Zen Browser policies and imports the profile modules undermodules/aspects/_browser/. - The
homebrewaspect installs Hammerspoon. Thehammerspoonaspect linksmodules/aspects/_hammerspoon/to$HOME/.hammerspoonthrough Home Manager. import-treeskips paths containing/_. This keeps implementation files undermodules/aspects/_*/, including the NVF source, out of automatic loading.- nix-darwin hosts Home Manager, so the flake does not expose a standalone
homeConfigurationsoutput.
Adding a host
- Create
hosts/<hostname>.nix. - Set
repo.hosts.<hostname>.system. - List the required aspects in
repo.hosts.<hostname>.features. - Put host-specific behavior in a new aspect under
modules/aspects/instead of changing a shared feature.
Secrets
- Keep secrets encrypted in
secrets/*.yaml. .sops.yamldefines the encryption rules forsecrets/.*\.yaml.- The
secretsaspect reads:secrets/github.yaml:github_ssh_key,github_cli_tokensecrets/ssh.yaml:kmeat_mac_mini_ssh_key
Troubleshooting
- Run
just debug <hostname>for detailed evaluation and build logs. - If a host fails to evaluate, check that it exists in
darwinConfigurations. - Run
just dry-run <hostname>to check evaluation and dependency resolution without switching. - If a successful build leaves stale settings, run
just switch <hostname>again and check the active hostname and configuration values.