Nix is a purely functional package manager that aims to make package management reliable and reproducible.
There are three choices for installing Nix: the native Arch Linux package, the upstream installation script officially supported by Nix, and the "Zero to Nix" script provided by Determinate Systems, a company providing third party support for Nix.
Install the package.
Upstream installation script
Download the file with
curl --proto '=https' --tlsv1.2 -sSfL https://nixos.org/nix/install -o nix-install.sh, view it:
less ./nix-install.sh, and run the script
./nix-install.sh --daemon to start Nix installation.
curl some-url | sh, as the Nix documentation suggests, is considered as a security risk, because it executes unknown code. Therefore it is recommended to manually download the script and check it, before executing it.
Zero to Nix installation script
For an easier and less complicated Nix setup you can use the setup from Determinate Systems. Download the file with
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix -o nix-install.sh, view it:
less ./nix-install.sh, and run the script
sh ./nix-install.sh install to start the installation.
curl some-url | sh, as Determinate Systems suggests, is considered as a security risk, because it executes unknown code. Therefore it is recommended to manually download the script and check it, before executing it.
sh ./nix-install.sh install --diagnostic-endpoint="".
For more information see the manual from Determinate Systems.
To have the Nix daemon launched at boot time, enable
Add required users to the
nix-users group in order to access the daemon socket.
Add a channel and update it.
$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable $ nix-channel --update
With the shell configured, the following should install hello into your updated PATH:
If you installed Nix from the official repositories, you must add the
~/.nix-profile/bin directory to your PATH manually.
$ nix-env -iA nixpkgs.hello
hello and make sure it is in the right PATH. If it works, you can remove it simply by
$ nix-env --uninstall hello
Or you can check the list of installed program by (q stands for query)
$ nix-env -q
You can also check generations by
$ nix-env --list-generations
Check more details in themanual.
Tips and tricks
By default, nix only uses one builder. The following will allow nix to use as many jobs as the number of CPUs:
max-jobs = auto
To run OpenGL and Vulkan applications, use NixGL.
For integrating Nix applications with your desktop environment, add the
~/.nix-profile/share directory to your
$XDG_DATA_DIRS, for instance using
Zsh integration for nix-shell
nix-zsh-completions provides Zsh completions for nix commands such as
nix repl or
nix-env -u as user produces
cannot connect to daemon at '/nix/var/nix/daemon-socket/socket: permission denied
If you just installed nix, you need to reboot.
Too many open files
Some builds may run into an error such as
error: opening directory '/nix/store/...': Too many open files
nix-daemon.service and increase the file limit
Warning message about root user channels
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
If the above message shows up when using Nix, the root user will need to update their channels.
# nix-channel --update
warning: Nix search path entry '/nix/var/nix/profiles/per-user/<USER>/channels' does not exist, ignoring
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
Sandbox build issues
Other sandbox issues
error: while setting up the build environment: mounting /proc: Operation not permitted error: program '/usr/bin/nix-env' failed with exit code 1
1: package 'utils' in options("defaultPackages") was not found 2: package 'stats' in options("defaultPackages") was not found Error: .onLoad failed in loadNamespace() for 'utils', details: call: system(paste(which, shQuote(names[i])), intern = TRUE, ignore.stderr = TRUE) error: cannot popen '/nix/store/fnkvlbls29d01jcx3wsdnhykyrl7087r-which-2.21/bin/which 'uname' 2>/dev/null', probable reason 'Cannot allocate memory'
nixpkgsexpects to be built with the sandbox on.
The most common fix is to disable sandboxing in the configuration file, then Restart the
# disable sandboxing sandbox = false
The Nix wiki recommends running
export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive. Alternatively, export the environment variable