My personal Nix flake for home-manager on macOS.
-
Install Nix package manager:
curl -L https://nixos.org/nix/install | bash -s -- --daemon
You can also replace the install URL with a specific version such as
https://releases.nixos.org/nix/nix-2.18.2/install
(this setup has been verified to work on at least2.18.2
). -
If the per-user profile directory doesn't exist for your user at
/nix/var/nix/profiles/per-user/$(whoami)
, create it:sudo install -d -o $(whoami) /nix/var/nix/profiles/per-user/$(whoami)
(
install
is the same asmkdir
followed bychown
) -
Install home-manager and activate the
personal
config while in this directory:$( nix build \ --extra-experimental-features "nix-command flakes" \ --no-link \ --print-out-paths \ ".#homeConfigurations.personal.activationPackage" )/activate
Note that the
personal
config targetsaarch64-darwin
, so you may need to updateflake.nix
if on a different platform (such asx86_64-darwin
).
After making changes to config, you can rebuild with:
home-manager switch --flake ".#personal"
To apply changes without being in this directory, replace .
with the path to
this directory.
Note the --extra-experimental-features
flag isn't needed because our
home-manager config (via the flakes module) adds the relevant lines to
~/.config/nix/nix.conf
.
Dependencies are defined in flake.nix
and versions are pinned in flake.lock
.
-
To update all dependencies:
nix flake update
-
To update a specific depedency (such as
nixpkgs
):nix flake lock --update-input nixpkgs
Some related GitHub issues for context:
There are various levels of cleanup you can do:
# Clean up files not used by any generations of the current profile
nix-collect-garbage
# Clean up files not used by the current generation of the current profile
nix-collect-garbage -d
# Clean up files not used by the current generation for any profile
sudo nix-collect-garbage -d
In the past, it has been recommended to also run sudo mdutil -i off /nix
after installation to disable spotlight indexing, but recent versions of the
installer set the nobrowse
option in the mount options, accomplishing the
same thing. See the macOS installation section of the documentation for
details.
Some resources I found useful during setup: