Installing Nix on macOS Catalina
Tags: nix, macos, howto
Published: 2020-04-28 01:06:18

**UPDATE (2020-06-12):** Nix 2.3.5 has introduced command line option `--darwin-use-unencrypted-nix-store-volume` to do the following. ([Documentation](https://hydra.nixos.org/build/119559243/download/1/manual/#sect-macos-installation))

To install Nix on macOS Catalina, run:

    sh <(curl https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume

------

Installing [Nix](https://nixos.org/nix/) on macOS Catalina following the instruction in the "Get Nix" button would abort with the following error as of 2020-04-27:

    mkdir: /nix: Read-only file system

The installation script would suggest you manually create the `/nix` folder but you'd receive the same error. This is because in macOS Catalina the root `/` is mounted read-only, to protect system components from being tampered with.

To workaround this, Nix team has written a script to create a new APFS volume and mount at `/nix`. To run the script:

```
curl -L https://raw.githubusercontent.com/NixOS/nix/d42ae78de9f92d60d0cd3db97216274946e8ba8e/scripts/create-darwin-volume.sh | sh
```

If successful, you'd see output like:

```
     ------------------------------------------------------------------
    | This installer will create a volume for the nix store and        |
    | configure it to mount at /nix.  Follow these steps to uninstall. |
     ------------------------------------------------------------------

  1. Remove the entry from fstab using 'sudo vifs'
  2. Destroy the data volume using 'diskutil apfs deleteVolume'
  3. Remove the 'nix' line from /etc/synthetic.conf or the file

Configuring /etc/synthetic.conf...
Password:
nix
Creating mountpoint for /nix...
Creating a Nix Store volume...
Will export new APFS Volume "Nix Store" from APFS Container Reference disk1
Started APFS operation on disk1
Preparing to add APFS Volume to APFS Container disk1
Creating APFS Volume
Created new APFS Volume disk1s6
Mounting disk
Setting volume permissions
Disk from APFS operation: disk1s6
Finished APFS operation on disk1
Configuring /etc/fstab...
123
164

The following options can be enabled to disable spotlight indexing
of the volume, which might be desirable.

   $ sudo mdutil -i off /nix
```

Go ahead and disable spotlight indexing for `/nix`. You don't need to index a cache.

Now that `/nix` is available, the official installation instruction works:

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

Happy nixing!

```
nix --version
nix (Nix) 2.3.4
```

The script comes from [NixOS/nix#3212](https://github.com/NixOS/nix/pull/3212):

{% github https://github.com/NixOS/nix/pull/3212 %}

This issue is being discussed at [NixOS/nix#2925](https://github.com/NixOS/nix/issues/2925).

{% github https://github.com/NixOS/nix/issues/2925 %}

---

1. I am installing Nix to build [Ormolu](https://github.com/tweag/ormolu), a formatter for Haskell source code.

---

If you feel that you've got something from this post, I am glad! Please don't hesitate to comment or reach out.

If you feel that you've got enough that you'd like to donate, please [donate to Wikimedia Foundation](https://donate.wikimedia.org), to which I owe infinitely.