The easiest way to install Nix is to run the following command:
$ sh <(curl -L https://nixos.org/nix/install)
This will run the installer interactively (causing it to explain what it is doing more explicitly), and perform the default "type" of install for your platform:
single-user on Linux
multi-user on macOS
Notes on read-only filesystem root in macOS 10.15 Catalina +
- It took some time to support this cleanly. You may see posts, examples, and tutorials using obsolete workarounds.
- Supporting it cleanly made macOS installs too complex to qualify as single-user, so this type is no longer supported on macOS.
We recommend the multi-user install if it supports your platform and
you can authenticate with
To explicitly select a single-user installation on your system:
$ sh <(curl -L https://nixos.org/nix/install) --no-daemon
This will perform a single-user installation of Nix, meaning that
is owned by the invoking user. You should run this under your usual user
account, not as root. The script will invoke
sudo to create
if it doesn’t already exist. If you don’t have
sudo, you should
/nix first as root, e.g.:
$ mkdir /nix $ chown alice /nix
The install script will modify the first writable file from amongst
.profile to source
~/.nix-profile/etc/profile.d/nix.sh. You can set the
NIX_INSTALLER_NO_MODIFY_PROFILE environment variable before executing
the install script to disable this behaviour.
You can uninstall Nix simply by running:
$ rm -rf /nix
The multi-user Nix installation creates system users, and a system service for the Nix daemon.
- Linux running systemd, with SELinux disabled
You can instruct the installer to perform a multi-user installation on your system:
$ sh <(curl -L https://nixos.org/nix/install) --daemon
The multi-user installation of Nix will create build users between the
user IDs 30001 and 30032, and a group with the group ID 30000. You
should run this under your usual user account, not as root. The script
sudo as needed.
If you need Nix to use a different group ID or user ID set, you will have to download the tarball manually and edit the install script.
The installer will modify
/etc/zshrc if they exist.
The installer will first back up these files with a
extension. The installer will also create
sudo rm -rf /etc/profile/nix.sh /etc/nix /nix ~root/.nix-profile ~root/.nix-defexpr ~root/.nix-channels ~/.nix-profile ~/.nix-defexpr ~/.nix-channels # If you are on Linux with systemd, you will need to run: sudo systemctl stop nix-daemon.socket sudo systemctl stop nix-daemon.service sudo systemctl disable nix-daemon.socket sudo systemctl disable nix-daemon.service sudo systemctl daemon-reload
There may also be references to Nix in
/etc/zshrc which you may remove.
/etc/bashrcto remove the lines sourcing
nix-daemon.sh, which should look like this:
# 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 these files haven't been altered since installing Nix you can simply put the backups back in place:
sudo mv /etc/zshrc.backup-before-nix /etc/zshrc sudo mv /etc/bashrc.backup-before-nix /etc/bashrc
This will stop shells from sourcing the file and bringing everything you installed using Nix in scope.
Stop and remove the Nix daemon services:
sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist sudo launchctl unload /Library/LaunchDaemons/org.nixos.darwin-store.plist sudo rm /Library/LaunchDaemons/org.nixos.darwin-store.plist
This stops the Nix daemon and prevents it from being started next time you boot the system.
nixbldgroup and the
sudo dscl . -delete /Groups/nixbld for u in $(sudo dscl . -list /Users | grep _nixbld); do sudo dscl . -delete /Users/$u; done
This will remove all the build users that no longer serve a purpose.
Edit fstab using
sudo vifsto remove the line mounting the Nix Store volume on
/nix, which looks like this,
LABEL=Nix\040Store /nix apfs rw,nobrowse. This will prevent automatic mounting of the Nix Store volume.
/etc/synthetic.confto remove the
nixline. If this is the only line in the file you can remove it entirely,
sudo rm /etc/synthetic.conf. This will prevent the creation of the empty
/nixdirectory to provide a mountpoint for the Nix Store volume.
Remove the files Nix added to your system:
sudo rm -rf /etc/nix /var/root/.nix-profile /var/root/.nix-defexpr /var/root/.nix-channels ~/.nix-profile ~/.nix-defexpr ~/.nix-channels
This gets rid of any data Nix may have created except for the store which is removed next.
Remove the Nix Store volume:
sudo diskutil apfs deleteVolume /nix
This will remove the Nix Store volume and everything that was added to the store.
After you complete the steps here, you will still have an empty
/nixdirectory. This is an expected sign of a successful uninstall. The empty
/nixdirectory will disappear the next time you reboot.
You do not have to reboot to finish uninstalling Nix. The uninstall is complete. macOS (Catalina+) directly controls root directories and its read-only root will prevent you from manually deleting the empty
We believe we have ironed out how to cleanly support the read-only root on modern macOS. New installs will do this automatically, and you can also re-run a new installer to convert your existing setup.
This section previously detailed the situation, options, and trade-offs, but it now only outlines what the installer does. You don't need to know this to run the installer, but it may help if you run into trouble:
- create a new APFS volume for your Nix store
/etc/synthetic.confto direct macOS to create a "synthetic" empty root directory to mount your volume
- specify mount options for the volume in
noauto: prevent the system from auto-mounting the volume (so the LaunchDaemon mentioned below can control mounting it, and to avoid masking problems with that mounting service).
nobrowse: prevent the Nix Store volume from showing up on your desktop; also keeps Spotlight from spending resources to index this volume
- if you have FileVault enabled
- generate an encryption password
- put it in your system Keychain
- use it to encrypt the volume
- create a system LaunchDaemon to mount this volume early enough in the boot process to avoid problems loading or restoring any programs that need access to your Nix store
NixOS.org hosts version-specific installation URLs for all Nix versions
since 1.11.16, at
These install scripts can be used the same as the main NixOS.org installation script:
$ sh <(curl -L https://nixos.org/nix/install)
In the same directory of the install script are sha256 sums, and gpg signature files.
You can also download a binary tarball that contains Nix and all its
dependencies. (This is what the install script at
https://nixos.org/nix/install does automatically.) You should unpack
it somewhere (e.g. in
/tmp), and then run the script named
inside the binary tarball:
$ cd /tmp $ tar xfj nix-1.8-x86_64-darwin.tar.bz2 $ cd nix-1.8-x86_64-darwin $ ./install
If you need to edit the multi-user installation script to use different
group ID or a different user ID range, modify the variables set in the