How to restore Nix and Home Manager after macOS Upgrade?

I’ve just upgraded to macOS Ventura 13.2.1 and nix and home-manager are no longer accessible via a terminal.

Apps like iterm to libre office that I’ve installed via home manager are still working, whereas cli apps like helix editor to bat are no longer working.

It appears the issue is that my /etc/zshrc file that had the following it from the nix installer, has been replaced by the upgrade (whereas my /etc/zshenv was untounched by it):

# Nix
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
  . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
# End Nix

I feel like a complete newb, because I’m struggling to put that back in to (hopefully) give me access to nix and home-manager commands again. I’ve tried using sudo and directly editing the file as root user, but still am told that /etc/zshrc is read only.

Normally I can easily find a stackoverflow or other post to fix this, but have not, which is why I’m asking here… and also to learn how people usually prepare and react to such OS upgrades (eg backup files - as I have, write particular files from nix and home-manager back, etc)?

Solved by booting into recover mode (holding Option while booting), choosing Terminal from Utilities, entering csrutil disable at the prompt to disable Apple’s SIP,

and after booting into macOS as per usual and logging in, then in a terminal: sudo vim /etc/zshrc and adding:

# Nix
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
  . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
# End Nix

to the end of the file, and wq! (as Vim still complains that the file is read-only without the !). I could have restarted iTerm/a terminal, but rebooted just to be sure, and nix and home-manager and cli apps installed via them are now working.

After rebooting (that last time), I ran home-manager switch in case anything needed to reinstall because I had upgraded macOS, but it appears that didn’t reinstall anything.

It sounds like vim is being picky. nano doesn’t complain (but I do see the same warning when I try to edit it with vim). You could probably also explicitly chmod the file to be root-writable.

FWIW, you don’t need to disable SIP to do this. Nix wouldn’t even be able to install if SIP had to be disabled to edit this file.

3 Likes

Thanks @abathur!

That’s good to know.

I was going to ask how the nix install script got around this, but then thought I must have disabled SIP after my previous install of macOS to be able to edit files in /etc, and guessed that may have been how nix created its volume and modified the file.

I have a copy of the nix install script’s detailed explanation of its process, so I must have a look at it. Cheers!

Related: Nix-* commands missing after macOS 12.1 version upgrade - #8 by NobbZ

1 Like