Poby's nix-darwin setup
Find a file
2026-03-26 09:03:35 +09:00
.codex feat(codex): add codex config.toml 2026-03-24 20:59:38 +09:00
hosts refactor: migrate nix-darwin config to a flake-parts dendritic layout 2026-03-26 09:03:35 +09:00
modules refactor: migrate nix-darwin config to a flake-parts dendritic layout 2026-03-26 09:03:35 +09:00
secrets feat: add github_cli_token as sops secret 2026-03-15 02:50:21 +09:00
.gitignore feat(git): git signing with ssh 2026-03-15 02:50:35 +09:00
.sops.yaml feat: sops-nix configuration 2026-03-15 02:50:19 +09:00
AGENTS.md feat: add AGENTS.md 2026-03-15 02:50:28 +09:00
flake.lock refactor: migrate nix-darwin config to a flake-parts dendritic layout 2026-03-26 09:03:35 +09:00
flake.nix refactor: migrate nix-darwin config to a flake-parts dendritic layout 2026-03-26 09:03:35 +09:00
Justfile feat: add AGENTS.md 2026-03-15 02:50:28 +09:00
README-ko.md refactor: migrate nix-darwin config to a flake-parts dendritic layout 2026-03-26 09:03:35 +09:00
README.md refactor: migrate nix-darwin config to a flake-parts dendritic layout 2026-03-26 09:03:35 +09:00

nix-darwin

한국어

Declarative macOS setup with nix-darwin, home-manager, nix-homebrew, and sops-nix.

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)

Prerequisites

  • macOS on Apple Silicon (aarch64-darwin)
  • Nix with flakes enabled (nix-command + flakes)
  • just (command runner)
  • SOPS age key at:
~/.config/sops/age/keys.txt

Repository Layout

  • flake.nix: flake-parts entrypoint and flake inputs
  • Justfile: day-to-day commands (darwin, darwin-debug, fmt, up, gc)
  • modules/flake/: repo options, Darwin assembly, and shared context modules
  • modules/aspects/: auto-discovered aspect entry modules such as base, homebrew, shell, editor, and desktop
  • modules/aspects/_*/: ignored internal implementation trees that back the public aspect entry modules
  • hosts/: auto-discovered host declarations that register system and a flat features list
  • secrets/: encrypted secret files (poby.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)

# 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'

# Validate without realizing a full build
nix build .#darwinConfigurations.fenrir.system --dry-run --extra-experimental-features 'nix-command flakes'

# Inspect profile history / cleanup old generations
just history
just clean
just gc

Configuration Notes

  • flake.nix now uses flake-parts, keeps ./modules/flake explicit, and auto-discovers ./modules/aspects and ./hosts through import-tree.
  • hosts/fenrir.nix is the current host declaration and maps fenrir to one flat feature list.
  • modules/flake/darwin-configurations.nix assembles each hosts darwinConfigurations.<host> output and embeds Home Manager for user poby.
  • modules/aspects/ is the feature vocabulary for hosts. The current feature set is base, nix-core, system-packages, homebrew, macos-defaults, activation, fonts, sudo-auth, shell, cli-tools, git, ssh, secrets, terminal, editor, desktop, and fenrir.
  • The cli-tools aspect owns the CLI user tool set, including zoxide.
  • modules/aspects/_*/ contains implementation files that are intentionally not auto-loaded. import-tree skips paths containing /_, which is the repos convention for internal helpers and subtrees like the NVF source.
  • Home Manager is Darwin-integrated only in this phase; no standalone homeConfigurations output is exposed.

Adding A Host

  • Create hosts/<hostname>.nix.
  • Register repo.hosts.<hostname>.system.
  • Register repo.hosts.<hostname>.features with 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.yaml enforces encryption rules for secrets/.*\.yaml.
  • Home Manager reads from secrets/poby.yaml via the secrets aspect:
    • github_ssh_key
    • github_cli_token

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-run before 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.