Recently my Nix home-manager config sharted, this is how I fixed it

I had to reinstall Nix and home-manager recently on my Mac, because for some reason home-manager switch stopped working.

After a bit of searching and trying out a bunch of fixes I found what worked. The working solution started with a full reinstall of Nix, and that starts with emptying the generated Nix volume with disk utility. The workflow was roughly as follows:

  1. Empty nix volume with disk utility

  2. Install multi-user Nix

    1. bash <(curl -L https://nixos.org/nix/install) --daemon
  3. Do the following permission modifications. First creates directories that fit the new user directory model in Nix, and the second one fixes their ownership so that home-manager can access them. Here’s the issue that I found:

    1. sudo mkdir -m 0755 -p /nix/var/nix/{profiles,gcroots}/per-user/$USER

    2. sudo chown -R $USER:nixbld /nix/var/nix/profiles/per-user/$USER

  4. Run home-manager install (standalone)

    1. nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager

    2. nix-channel --update

    3. nix-shell '<home-manager>' -A install`

  5. Remove old configuration symlink

    1. rm -rf /Users/$USER/.config/home-manager
  6. Add a new symlink to your existing config (assuming your config lives in /Users/$USER/dev/personal/nixfiles, be sure to replace this with your own configuration location.

    1. ln -s /Users/$USER/dev/personal/nixfiles /Users/$USER/.config/home-manager
  7. Run home-manager switch and the thing should work!

The point of this blog was to gather my solution to a single location, hope it helps anyone who comes across the same issues I did.

Subscribe to jantto
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.