mirror of
https://github.com/smg1024/nix-darwin.git
synced 2026-07-21 20:51:43 +09:00
Poby's nix-darwin setup
- Nix 84.6%
- Lua 13.4%
- Just 2%
| .codex | ||
| dotfiles | ||
| hosts | ||
| modules | ||
| secrets | ||
| .gitignore | ||
| .sops.yaml | ||
| AGENTS.md | ||
| flake.lock | ||
| flake.nix | ||
| Justfile | ||
| README-ko.md | ||
| README.md | ||
nix-darwin
Declarative macOS setup with nix-darwin, home-manager, nix-homebrew, and
sops-nix. The flake assembles one or more macOS hosts from small aspect
modules, with Home Manager embedded through nix-darwin.
What this repo manages
- Flake orchestration and host assembly in
modules/flake/ - Auto-discovered Darwin and Home Manager aspects in
modules/aspects/ - Auto-discovered host declarations in
hosts/ - Encrypted secrets via SOPS (
secrets/+.sops.yaml) - Editor, browser, terminal, shell, desktop, SSH, and CLI tooling for user
poby
Prerequisites
- macOS on Apple Silicon (
aarch64-darwin) - Nix with flakes enabled (
nix-command+flakes) just(command runner)- SOPS age key at:
$HOME/.config/sops/age/keys.txt
Repository layout
flake.nix:flake-partsentrypoint and flake inputsJustfile: day-to-day commands (dry-run,darwin,darwin-debug,fmt,up,upp,repl,history,clean,gc,gcroot)modules/flake/: repo options, Darwin assembly, and shared context modulesmodules/aspects/: auto-discovered aspect entry modules such asbase,homebrew,shell,browser,discord,editor, anddesktopmodules/aspects/_*/: ignored internal implementation trees that back the public aspect entry modulesmodules/aspects/_hammerspoon/: Hammerspoon configuration linked to$HOME/.hammerspoonmodules/aspects/_editor/: NVF and Zed editor configurationmodules/aspects/_browser/: Zen Browser policies, profile settings, extensions, containers, spaces, and pinned tabsmodules/aspects/_secrets/:sops-nixdeclarations, age key wiring, and the Home ManagerSOPS_AGE_KEY_FILEsession variablehosts/: auto-discovered host declarations that registersystemand a flatfeatureslistsecrets/: encrypted secret files split by purpose (github.yaml,ssh.yaml)
Common commands
# List available tasks
just
# Build and switch for current machine hostname
just darwin $(hostname)
# Build and switch with trace/verbose logs
just darwin-debug $(hostname)
# Validate dependency graph without realizing a full build
just dry-run fenrir
# Format Nix files (from repository root)
just fmt .
# Update all flake inputs
just up
# Update one flake input
just upp nixpkgs
# Validate build without switching (example host: fenrir)
nix build .#darwinConfigurations.fenrir.system --extra-experimental-features 'nix-command flakes'
# Equivalent raw Nix dry-run validation
nix build .#darwinConfigurations.fenrir.system --dry-run --extra-experimental-features 'nix-command flakes'
# Inspect profile history / clean old generations / collect unused store paths
just history
just clean
just gc
Configuration notes
flake.nixusesflake-parts, keeps./modules/flakeexplicit, and auto-discovers./modules/aspectsand./hoststhroughimport-tree.hosts/fenrir.nixandhosts/huginn.nixdeclare the available macOS hosts and map each host to one flat feature list.modules/flake/darwin-configurations.nixassembles each host'sdarwinConfigurations.<host>output and embeds Home Manager for userpoby.modules/aspects/is the feature vocabulary for hosts. The current feature set isbase,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 owns the CLI user tool set, includingmarp-cliandzoxide. - The
editoraspect imports both NVF and Zed. Zed is configured through Home Manager with mutable user settings and keymaps enabled, thenixextension,nixdas the active Nix language server, and Alejandra as the Nix formatter. - The
browseraspect manages Zen Browser through Home Manager, including browser policies and the profile modules undermodules/aspects/_browser/. - The Hammerspoon app is installed through the
homebrewcask list, while thehammerspoonaspect linksmodules/aspects/_hammerspoon/to$HOME/.hammerspoonwith Home Manager. modules/aspects/_*/contains implementation files that are intentionally not auto-loaded.import-treeskips paths containing/_, which is the repo's convention for internal helpers and subtrees like the NVF source.- Home Manager is integrated through nix-darwin; no standalone
homeConfigurationsoutput is exposed.
Adding a host
- Create
hosts/<hostname>.nix. - Register
repo.hosts.<hostname>.system. - Register
repo.hosts.<hostname>.featureswith the desired aspect names. - Add any host-specific behavior as a new aspect in
modules/aspects/instead of modifying shared features.
Secrets
- Keep secrets encrypted in
secrets/*.yaml. .sops.yamlenforces encryption rules forsecrets/.*\.yaml.- Home Manager reads split SOPS files via the
secretsaspect:secrets/github.yaml:github_ssh_key,github_cli_tokensecrets/ssh.yaml:kmeat_mac_mini_ssh_key
Troubleshooting
- Use
just darwin-debug <hostname>for detailed evaluation/build output. - If evaluation fails for a host, verify it exists under
darwinConfigurations. - Dry-run evaluation with
nix build .#darwinConfigurations.<host>.system --dry-runbefore a full switch when you only want to confirm the dependency graph. - If settings look stale after a successful build, run switch again and verify active hostname/config values.