Nix

From ArchWiki
Jump to navigation Jump to search

Nix is a purely functional package manager that aims to make package management reliable and reproducible.

See the Nix Package Manager Guide for more information.

Installation

Nix is available as nixAUR.

Nix is installed by default in the /nix folder.

Installation using archlinux-nix

archlinux-nixAUR can be used to 'bootstrap' an Arch Linux compatible Nix system by setting up the required groups and permissions.

After installing nixAUR and archlinux-nixAUR, list the available commands:

$ archlinux-nix

To complete the installation, follow all of these steps:

Prepare Arch for the Nix installation:

# archlinux-nix setup-build-group  # setup build groups
# archlinux-nix bootstrap          # bootstrap the system

Configure a default Nix channel and update it:

$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable
$ nix-channel --update
$ nix-env -u

After first install, and before rebooting, activate Nix in each new shell:

$ source /etc/profile.d/nix{,-daemon}.sh

This makes Nix's daemon (and package manager) functional without rebooting. It update your PATH to Nix's liking. Check it by `echo $PATH`. Run this in each new shell session until you have restarted.

Test installation

With the shell configured, the following should install hello into your updated PATH: /nix/store/[hash]-hello-[version]/bin/hello.

$ nix-env -iA nixpkgs.hello

Run 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 the nix-env(1) manual.

Extra configuration

If using Nix with an unprivileged account is desired, run:

# chown -R $USER: /nix/var/nix/{gcroots,profiles}

If only using unprivileged Nix access, run to silence warning: Nix search path entry '...' does not exist:

# nix-channel --update