Nix-Darwin
nix-darwin is an opionated set of modules for managing configuration of macOS. It provides a centralized nix file for declaring system state.
Resources
Install
nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A installer
./result/bin/darwin-installer
The installer will ask if you want to edit the default configuration. At the time of this writing, it was necessary to add the following:
nix.extraOptions = ''
extra-platforms = aarch64-darwin x86_64-darwin
experimental-features = nix-command flakes
'';
After installing, the configuration will be located at
~/.nixpkgs/darwin-configuration.nix
.
On a fresh install, it was necessary to perform the following:
This allows nix-darwin
to manage the above file and will remove a warning
that's produced every time the environment is built. See this issue.
Uninstall
nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A uninstaller
./result/bin/darwin-uninstaller
Update
Update configuration
The configuration is managed by Chezmoi, to edit it:
The changes will automatically be applied by a Chezmoi trigger.
Update channel
To update the underlying channel:
Migrate
Homebrew
To migrate from an existing installation that depends mainly on brew
, the
following notes are helpful:
- List the currently installed packages:
brew list
- Search for an equivalent package:
nix-env -qaP | grep -i <package>
- Add the package to
~/.nixpkgs/darwin-configuration.nix
. - Rebuild the environment:
darwin-rebuild switch
. - Uninstall the package from
homebrew
:brew uninstall <package> --force
Searching packages using nix-env
can be slow, an alternative is to use the
web interface.