Installing a Binary Distribution If you are using Linux or macOS, the easiest way to install Nix is to run the following command: $ sh <(curl https://nixos.org/nix/install) As of Nix 2.1.0, the Nix installer will always default to creating a single-user installation, however opting in to the multi-user installation is highly recommended.
Single User Installation To explicitly select a single-user installation on your system: sh <(curl https://nixos.org/nix/install) --no-daemon This will perform a single-user installation of Nix, meaning that /nix 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 /nix if it doesn’t already exist. If you don’t have sudo, you should manually create /nix first as root, e.g.: $ mkdir /nix $ chown alice /nix The install script will modify the first writable file from amongst .bash_profile, .bash_login and .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
Multi User Installation The multi-user Nix installation creates system users, and a system service for the Nix daemon. Supported Systems Linux running systemd, with SELinux disabled macOS You can instruct the installer to perform a multi-user installation on your system: sh <(curl 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 will invoke 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/bashrc, and /etc/zshrc if they exist. The installer will first back up these files with a .backup-before-nix extension. The installer will also create /etc/profile.d/nix.sh. You can uninstall Nix with the following commands: 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 # If you are on macOS, you will need to run: sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist sudo rm /Library/LaunchDaemons/org.nixos.nix-daemon.plist There may also be references to Nix in /etc/profile, /etc/bashrc, and /etc/zshrc which you may remove.
APFS Volume Installation The root filesystem is read-only as of macOS 10.15 Catalina, all writable paths to a separate data volume. This means creating or writing to /nix is not allowed. While changing the default prefix would be possible, it's a very intrusive change that has side effects we want to avoid for now. For common writable locations firmlinks where introduced, described by Apple as a "bi-directional wormhole" between two filesystems. Essentially a bind mount for APFS volumes. However this is (currently) not user configurable and only available for paths like /Users. For special cases like NFS mount points or package manager roots synthetic.conf(5) provides a mechanism for some limited, user-controlled file-creation at /. This only applies on a reboot, but apfs.util can be used to trigger the creation (not deletion) of new entries. alice$ /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -B The simplest solution is creating a symlink with /etc/synthetic.conf to the data volume. (not recommended) nix /System/Volumes/Data/nix alice$ ls -l / lrwxr-xr-x 1 root wheel 25 Jan 1 2019 nix -> /System/Volumes/Data/nix However builds that detect or resolve this symlink will leak the canonical location or even fail in certain cases, making this approach undesirable. An empty directory can also be created using /etc/synthetic.conf, this won't be writable but can be used as a mount point. And with APFS it's relatively easy to create an separate volume for nix instead. nix alice$ sudo diskutil apfs addVolume diskX APFS 'Nix Store' -mountpoint /nix alice$ mount /dev/disk1s6 on /nix (apfs, local, journaled) This does make the installation more complicated, requiring both /etc/synthetic.conf as well as /etc/fstab # # Warning - this file should only be modified with vifs(8) # # Failure to do so is unsupported and may be destructive. # LABEL=Nix\040Store /nix apfs rw On macOS volumes are also mounted quite late, launchd services or other things that start during login will start before our volume is mounted. For these cases eg. wait4path must be used for things that depend on /nix. This new volume also won't be encrypted by default, and enabling is only possible interactively? diskutil apfs enableFileVault /nix -user disk
Installing a pinned Nix version from a URL NixOS.org hosts version-specific installation URLs for all Nix versions since 1.11.16, at https://releases.nixos.org/nix/nix-version/install. These install scripts can be used the same as the main NixOS.org installation script: sh <(curl https://nixos.org/nix/install) In the same directory of the install script are sha256 sums, and gpg signature files.
Installing from a binary tarball 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 install inside the binary tarball: alice$ cd /tmp alice$ tar xfj nix-1.8-x86_64-darwin.tar.bz2 alice$ cd nix-1.8-x86_64-darwin alice$ ./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 file named install-multi-user.