Declarative configuration for Darwin (macOS) and Linux systems using chezmoi, nix and home-manager.
-
Xcode Command Line Tools (required for building packages):
xcode-select --install
sh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply alankritjoshiThis will:
- Install
chezmoiand setup dotfiles in~/.local/share/chezmoi - Run
chezmoi apply-> run the.chezmoiscriptsand sync dotfiles - Install Nix and, if a Mac, setup nix-darwin
- Install common nixpkgs +
brewandmasfor Mac packages - Run home manager for some configs that are more nix-like
For changes to chezmoi-tracked files:
- Option 1
- Make changes to the synced config e.g.,
~/.config/nvim/init.lua. Test it out chezmoi re-add
- Make changes to the synced config e.g.,
- Option 2
- Make changes and save+push on exit with
chezmoi edit ~/.config/nvim/init.lua
- Make changes and save+push on exit with
- Small changes to exiting configuration files tracked by chezmoi
- Non-nix related changes
- For additions/removals of files, previous workflow will become annoying as those commands do not work on untracked files
- Previous workflow doesn't run chezmoi scripts that are sometimes necessary
chezmoi add <new file>andchezmoi destroywill have to be used in confunction withchezmoi re-add
Instead, do:
chezmoi cd- tocdinto~/.local/share/chezmoiwhich is source of truth from remote and includes all the scripts- Make any changes - add, delete, edit. Note that it won't be effective in the system yet
- Sync to system and make the changes effective with
chezmoi apply
- Large changes to Neovim configuration, including addition/removal of plugins
- Any changes to nix configuration, as those changes typically require execution of scripts
If dotfiles remote is ahead of configuration on the device, run chezmoi update to pull and apply the remote changes
nix flake updateSometimes, especially when debugging, script execution may need to be excluded
chezmoi apply --exclude scripts~/.local/share/chezmoi/ # Dotfiles repo
├── private_dot_config/
│ ├── nix/ # System configuration
│ │ ├── flake.nix # Main flake
│ │ ├── devshell.nix # Dev shells
│ │ ├── machines/ # Machine configs
│ │ └── modules/ # Modular configs
│ ├── fish/ # Fish shell
│ ├── aerospace/ # Window manager
│ └── nvim/ # Neovim config
├── key.txt.age # Rage `passphrase` encrypted key
├── private_dot_ssh/
│ └── encrypted_private_id_ed25519_*.age # Rage `Key` encrypted SSH Keys
├── .chezmoiscripts/ # Bootstrap scripts
└── CLAUDE.md # AI assistant guide
- Main
key.txtwas generated withrage-keygen -o key.txtandrageencrypted with passphrase askey.txt.age - SSH Key pair was generated for each machine
- Main
key.txtwas used torageencrypt SSH keys in.private_dot_ssh
- First time setup script run by chezmoi prompts user for passphrase to rage decrypt
key.txt.age - Once decrypted in
~/.config/chezmoi/key.txt, chezmoi automatically uses it to rage decrypt the ssh keys and puts them in~/.ssh
# Move conflicting files
sudo mv /etc/nix/nix.conf /etc/nix/nix.conf.before-nix-darwin
chezmoi apply# Detailed error trace
darwin-rebuild build --flake ~/.config/nix#$(hostname -s) --show-traceIf you get errors like error: opening file '/nix/store/...-user-dbus-services.drv': No such file or directory:
# 1. Find what references the missing derivations
sudo nix-store --query --referrers /nix/store/missing-file.drv
# 2. Delete the chain of problematic derivations
sudo nix-store --delete --ignore-liveness \
/nix/store/problematic-derivation-1.drv \
/nix/store/problematic-derivation-2.drv
# 3. Clean up the nix database
sudo sqlite3 /nix/var/nix/db/db.sqlite \
"DELETE FROM ValidPaths WHERE path LIKE '%missing-derivation%';"
# 4. Clear caches and rebuild
rm -rf ~/.cache/nix/*
sudo rm -rf /tmp/nix-*
chezmoi applysudo darwin-rebuild rollback- Always use
chezmoi apply- never rundarwin-rebuilddirectly - Unknown hostname: Script will prompt to select configuration
MIT