Nix logo

Installing Nix on macOS Catalina isn’t hard if you know a little about APFS.

I’m the only user on my MacBook Pro so I don’t install using daemon mode, you can easily custom it (last step).

Step 1: synthetic.conf

It’s the way to create a folder in /

echo 'nix' | sudo tee -a /etc/synthetic.conf

Step 2: reboot

We need to reboot to apply the change about synthetic.

After reboot, you have /nix created

Step 3: creating a new volume

It’s the magic about APFS and attach it to /nix

sudo diskutil apfs addVolume disk1 APFSX Nix -mountpoint /nix

I’m the owner of the new volume

sudo diskutil enableOwnership /nix

We hide /nix and auto-mount the new volume to /nix at boot

echo "LABEL=Nix /nix apfs rw" | sudo tee -a /etc/fstab

Disable spotlight (indexing) on /nix

sudo mdutil -i off /nix

Step 4: install

curl -L https://nixos.org/nix/install | sh

Step 5: user config

We can replace and standardize each nix-env -i pkg_name with a config file: $HOME/.config/nixpkgs/config.nix

An example:

{
    allowUnfree = true;

    packageOverrides = pkgs: with pkgs; {
        all = pkgs.buildEnv {
            name = "all";
            paths = [
                ansible
                ansible-lint
                cloc
                colordiff
                dos2unix
                ffmpeg-full
                htop
                httpie
                jq
                mtr
                pwgen
                silver-searcher
                tmux
                tree
                watch
                wget
                whois
                yq
                zsh
                zstd
            ];
        };
    };
}

And to apply this config file: nix-env -i all

Step 6: my alias to upgrade and clean old version

nixupgrade='nix-channel --update && nix-env -u && nix-collect-garbage -d'