Installing nix on macOS Catalina
Nix is an extremely powerful package manager that uses a declarative functional programming language to describe dependencies. It stores all packages and build outputs in the nix store located at /nix
. This makes it slightly tricky to install on macOS 10.15 (Catalina), because the new read only system volume would prevent creating or writing to /nix
. A common workaround is to create a separate writable APFS volume and mount it at /nix
.
Before you start
- As of May 21, 2020, this workaround has been baked directly into the nix installer. However, out of an abundance of caution, it will only work if you don't use FileVault encryption or your Mac is a 2018 or newer model with a T2 chip.
- If you use this workaround, your nix store will be unencrypted.
- If you use this workaround, you will not be able to install nix in multi-user mode.
The workaround
Try a normal install
Head over to https://nixos.org/download.html and follow instructions. It might work! Otherwise, if you see the following error, continue with the workaround.
error: refusing to create Nix store volume because the boot volume is
FileVault encrypted, but encryption-at-rest is not available.
Manually create a volume for the store and re-run this script.
Create a mount point
Create a root-level mount point at /nix
using synthetic.conf
(run man synthetic.conf
in your terminal to find out more)
echo 'nix' | sudo tee -a /etc/synthetic.conf # or edit this file and just add nix
/System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B
[ 0 -ne "$?" ] && echo "Restarting APFS failed, please reboot your computer"
Reboot if it asks you to reboot.
Create an APFS volume
The following commands will create an APFS volume called Nix, mount it at /nix
hide it from the Finder sidebar, and configure it to be mounted at boot.
sudo diskutil apfs addVolume disk1 APFSX Nix -mountpoint /nix # make sure disk1 is correct
sudo diskutil enableOwnership /nix
sudo chown -R $(whoami) /nix
sudo chflags hidden /nix # if you don't want to see Nix volume in finder
echo "LABEL=Nix /nix apfs rw" | sudo tee -a /etc/fstab
Install Nix
Now you can install nix as normal.
curl https://nixos.org/nix/install | sh
References
This workaround was described and implemented by Daiderd Jordan. I mostly just followed along in the GitHub issue and took notes to help myself and others get up and running on macOS Catalina. The Nix manual has a section on macOS installation with lots of details also.