Hi, I have nix installed on my MacOS Monterey. Sadly I’m running out of space on the laptop and I’d like to make nix to use the external drive as its store (i.e. by symlinking). How to do it properly? I guess I’d need to copy the /nix
catalogue contents into the drive, get rid of the Nix Store volume and then symlink the drive to /nix
. Am I on a good track here?
While I haven’t tried it myself, IIUC a symlinked store can cause problems with some software. But the store volume doesn’t have to live on the same drive as /
.
If starting over isn’t prohibitive, it’s probably easiest to follow the uninstall instructions (Installing a Binary Distribution) and then set the appropriate variables to specify a different disk before installing:
If starting over is prohibitive, it’ll be a little more DIY–but there’s inevitably some way to duplicate the existing volume to a new disk and then update /etc/fstab and /Library/LaunchDaemons/org.nixos.darwin-store.plist to specify the new volume’s UUID (fair warning: this will be more complicated if you’re using FileVault).
I’ll describe what I’ve done in case someone needs to do it on their own. The following steps seem to be working:
- Install
nix
in a conventional way. This will create/nix
entry in/etc/synthetic.conf
and/nix
entry in/etc/fstab
. - Connect external drive. I formatted it to encrypted, case-sensitive APFS. Save the disk’s UUID (it’s shown in Disk Utility info and in
diskutil apfs list
).rsync
the contents of/nix
to this drive. - Delete the
/nix
disk created by the installer withsudo diskutil apfs deleteVolume /nix
. - Using
sudo vifs
, edit/etc/fstab
to point/nix
to your disk’s UUID. For me,
mateusz@Mateuszs-MacBook-Pro ~ % cat /etc/fstab
UUID=EBC0B7AA-1BD5-4F56-A677-6BDD47AC95F5 /nix apfs rw,noauto,nobrowse,suid,owners
This way, your disk will be automatically mounted to /nix
when connected.
- Reboot.
- Connect the disk, if it’s not connected. With
noauto
it shouldn’t mount automatically; open Disk Utility and mount. This should automatically mount it to/nix
. - Voila! Open the terminal and see whether the shortcuts to
nix
are sourced properly.
After first reboot, I had an issue with OS telling me that some nix software (the daemon I think) comes from an unknown source and won’t be launched. I opened security settings and allowed it from there.
This is why I said to update /Library/LaunchDaemons/org.nixos.darwin-store.plist
to specify the new volume’s UUID.
I’ll also reiterate that this will be more complicated for anyone trying to follow along with FileVault enabled. In that case, the installer creates an encrypted volume and stores the passphrase in your system keychain (using the volume UUID) and generates a slightly different mounting service to request this passphrase and use it to decrypt the volume.
The external disk/volume may or may not be encrypted (i.e., it is up to you if you are manually generating the volume)–and you’ll need to square these parts if you adapt an existing install. If you don’t encrypt the volume, you can use the below as a reference for how to replace the command in /Library/LaunchDaemons/org.nixos.darwin-store.plist
:
If you do encrypt your disk/volume, you’ll need to update the UUIDs in the plist and put the passphrase in the system keychain. You can see how the installer encrypts the volume and stores the credential in:
I have FileVault enabled, if that’s relevant.
Indeed. I updated the previous response to leave more breadcrumbs.
Thank you for the clarifications.