Install Directory for Nix on Mac

I am on Macbook Pro M1 Monterey and I restarted by machine. Nix executables could not be found. So I did a search for them and found a whole bunch of them below.

So I want to know the default location for a fresh install of nix. Reinstalling is complicated so I would rather just try to reset the path variable. I would also suggest “Nix Store” with a space is a bit unusual place to find a bin directory.

I am assuming that the one I want is the 2.8.0 but I don’t recall seeing this in $PATH before.

/System/Volumes/Data/Volumes/Nix Store/store/srdy89xwb4zbhigvyj3nkl910r7ldyrn-nix-2.3.15/bin/nix-shell

/System/Volumes/Data/Volumes/Nix Store/store/lqwm6k7gfjm6pg7jqdp68wl042qa30pk-nix-2.7.0/bin/nix-shell

/System/Volumes/Data/Volumes/Nix Store/store/izc9592szrnpv8n86hr88bhpyc9g6b4s-nix-2.8.0/bin/nix-shell

/System/Volumes/Data/Volumes/Nix Store/store/01rws9ixr9qp3cqv305kdr1np8n2qjqr-nix-2.3.16/bin/nix-shell

The default location is indeed in the store, though there is a generated script that knows how to find nix properly.

Make sure to source it from your users shell rc, rather than from the system.

Check the installation manual for where to find the script, as it lives in different locations depending on whether you did a multi or single user installation.

https://nixos.org/manual/nix/stable/installation/installing-binary.html

Alternatively redo the changes the installer does in the system wide shell RC files, but be aware that Apple loves to overwrite them on updates.

This problem gets reported in the various chats regularly.

That’s annoying. In my MacBook I did a multi-user install. I only see the following related to nix in /etc/zshrc

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

  • If you rebooted because you updated macOS, the problem is probably, as nobbz mentions, Apple’s update overwriting /etc/zshrc. AFAIK they generally don’t clobber /etc/bashrc, so you can find a copy of the shell hook at the end of that file and re-add it to /etc/zshrc.
  • If you didn’t update macOS (which you comment about still seeing the hook in zshrc suggests), the problem is presumably that something else in your shell profile is overriding. This generally takes the form of something that runs before the shell hook aborting early, or something afterwards (often in your user profile) hard-setting the PATH instead of merely prepending/appending.

Actually… I’m probably getting ahead of us. The paths you’re citing (/System/Volumes/Data/Volumes/Nix Store) may mean something more fundamental isn’t working.

The store is on its own volume which should be mounted at /nix, so make sure you see /nix/store (i.e., run ls /nix/store). If not, the problem is probably whatever is keeping your store volume from mounting. Your shell hook may be fine.

1 Like

Well I had two users on my Macbook one seems to have been created by Nix called Other then I added another admin user. When I rebooted it asked for admin permission because of multiple users being affected which I provided, and after that it seemed to have overwritten /etc/zshrc

Actually it does not see /nix

nix % sudo ls /nix
Password:
ls: /nix: No such file or directory

Do you have /etc/synthetic.conf and /etc/fstab? What do they contain?

This should be taken care of as a synthetic mount if you followed the directions from sh <(curl -L https://nixos.org/nix/install)

[11:50:16] jon@Jonathans-Mac-mini ~
$ df | grep nix
/dev/disk3s7    478724992 138466432 251243648    36% 3151936 1256218240    0%   /nix

cat /etc/synthetic.conf

cat: /etc/synthetic.conf: No such file or directory

% cat /etc/fstab

UUID=9D26308A-5246-4280-9DB2-10913B6FAA82 apfs rw,noauto,nobrowse,suid,owners

I’m not sure how it got removed, but this is probably your problem.

The file should contain nix on a line by itself. You can do this with an editor if you like, but you can also run the equivalent of what the installer does:

sudo /usr/bin/ex --noplugin /etc/synthetic.conf <<EOF
:a
nix
.
:x
EOF

Ok, it probably had to do my having tried run a second install of nix from the other admin user. I was trying to do a fresh install and dev environment under a new user and perhaps that affected it.

After you confirm that the file contains nix on a line by itself, reboot, and confirm that /nix is mounted.

/nix is now there but I don’t see anything under it

/nix % ls -la
total 0
drwxr-xr-x 2 root wheel 64 Apr 28 02:03 .
drwxr-xr-x 20 root wheel 640 Feb 26 14:05 .

What I recall is that fstab had /nix appearing just before or after apfs I think like below:
UUID=9D26308A-5246-4280-9DB2-10913B6FAA82 /nix apfs rw,noauto,nobrowse,suid,owners
I did modify this once during an uninstall but after that it reinstalled successfully and I had been using nix commands ok

The uninstall recommendation was to remove nix from fstab and I removed just the directory perhaps it was the entire line that should have been removed during the uninstall.

Egh. So, what you’re seeing now is the empty mountpoint for the volume (created by macOS based on synthetic.conf). Since your volume isn’t mounted, there’s some kind of inconsistent state between fstab, the actual volume(s) on your system, and the mounting service script (stored in /Library/LaunchDaemons/org.nixos.darwin-store.plist).

You’re right that /nix should be present in the fstab between the UUID and apfs (and, yes–the instructions meant to remove the entire line).

We can keep trying to debug, but TBH it will probably be faster to follow the uninstall instructions at Installing a Binary Distribution again (with the complete removal of the line from fstab, and with an edit to the 7th step–just manually open Disk Utility and delete any/all volumes named Nix Store), and try a fresh install.

Ok, just wondering how does this affect the nix stores used in my existing project where I ran nix-shell? I think it downloaded lots of items over a few hours. Would those be lost on a reinstall? Not a huge loss, I am just curious if these stores are separate or not?

Yes. If avoiding that is important, you’ll have to manually fix up…

  • fstab needs /nix as you noted, and you need to make sure it uses the UUID of the right volume. run diskutil apfs list and:
    • make sure there’s only one “Nix Store” volume. If not, you’ll want to figure out which one is the right volume and delete the other.
    • locate the UUID of the correct volume. It appears at the end of the first line of output for each volume (the one that begins +->)
  • ensure /Library/LaunchDaemons/org.nixos.darwin-store.plist exists and contains a mount command that uses the same volume UUID.
    • If you aren’t using FileVault, the rough format is /usr/sbin/diskutil mount -mountPoint "$mountpoint" "$volume_uuid"
    • If you are using FileVault, the rough format is /usr/sbin/diskutil apfs unlockVolume '$volume_uuid' -mountpoint '$mountpoint' -stdinpassphrase"

Ok, I am quite sure that the older versions of nix were not installed by me. Perhaps they were preinstalled on the MacOS Monterey?

In terms of determining which store is the correct one is there anyway to go from the item in the store to find this? For example I see this during the original compilation

/nix/store/wqqhy3rnvd4gb7fmwzc69slyp6n734dr-ghcide-lib-ghcide-1.5.0.1.drv

Is there any information in this entry that would tell me which store is involved?