Nix-darwin setup for an M3 mac, a variant of nix for macs.
- Install Nix, multi-user installation.
- Install Homebrew. Not strictly necessary, but some apps are not in nixpkgs, and nix integrates nicely with homebrew.
- Clone this repository to
~/.config/nix-darwin
- Install nix-darwin, using nix itself, and nix flakes
nix --extra-experimental-features 'nix-command flakes' \
run nix-darwin -- switch --flake ~/.config/nix-darwin
darwin-rebuild switch --flake ~/.config/nix-darwin
(needs root)
- flake.nix
- main entrypoint
- systems configuration: only one for a single mac
- dependency setup: inputs with locked versions
- configured with China mirrors for faster downloads
- flake.lock
- pinned versions of all dependencies
- modules/
- apps.nix: system and homebrew packages, environment variables
- host-users.nix: machine and user setup
- nix-core.nix: configuration of nix itself on the machine
- system.nix: mac specific settings; dock, keyboard, finder++
- home/
- home manager modules: user specific package configuration
- most of these modules are pulled in from jiaqiwang969/nix-home-manager
- includes configurations for:
- GPG and SSH keys
- Git configuration
- Terminal tools (alacritty, tmux)
- Development tools (emacs, neovim)
- Window management (yabai, skhd)
- Multiple package channels:
- nixpkgs-darwin (23.11 stable)
- nixpkgs-unstable (latest unstable)
- nixpkgs-locked (specific version for compatibility)
- China mirrors configuration for faster downloads
- Integrated development environment setup
- Automated system maintenance
- Custom overlays and patches
All dependencies are locked to specific versions for reproducibility:
- nixpkgs-darwin (2024-01-31): nixpkgs for macOS
- nix-darwin (2024-03-01): nix support for configuring macs
- home-manager (2024-01-30): user specific package configuration
- nixpkgs-firefox-darwin (2024-01-21): firefox built for darwin
- Custom configurations:
- nix-home-manager (2024-01-23): personal home-manager config
- dotfiles (2024-01-30): personal dotfiles
Update all dependencies:
nix flake update
Update a single input:
nix flake lock --update-input <input-name>
# Example:
nix flake lock --update-input nixpkgs-firefox-darwin
After updating, rebuild the system:
darwin-rebuild switch
Clean up old generations:
nix-collect-garbage -d
Optimize store:
nix store optimise
If you encounter issues with applications:
- Check the nix logs:
journalctl -u nix-daemon
- Clean up and rebuild:
nix-collect-garbage -d darwin-rebuild switch
- Update flake lock file if needed:
nix flake update