Nix: Difference between revisions
Grawlinson (talk | contribs) (Undo revision 732521 by Randomnerd (talk) this applies to every single package that utilises systemd tmpfiles/sysusers) Tag: Undo |
Lahwaacz.bot (talk | contribs) (update Pkg/AUR templates) |
||
(39 intermediate revisions by 13 users not shown) | |||
Line 6: | Line 6: | ||
== Installation == | == Installation == | ||
There are | 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. | ||
=== Native === | === Native === | ||
Line 14: | Line 14: | ||
=== Upstream installation script === | === Upstream installation script === | ||
Download the file with {{ic|curl --proto ' | Download the file with {{ic|curl --proto '{{=}}https' --tlsv1.2 -sSfL <nowiki>https://nixos.org/nix/install</nowiki> -o nix-install.sh}}, view it: {{ic|less ./nix-install.sh}}, and run the script {{ic|./nix-install.sh --daemon}} to start Nix installation. | ||
{{Warning|Running {{ic|curl ''some-url'' {{!}} sh}}, as the Nix documentation suggests, is considered as a security risk, because it executes unknown code, | {{Warning|Running {{ic|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 {{ic|curl --proto '{{=}}https' --tlsv1.2 -sSf -L <nowiki>https://install.determinate.systems/nix</nowiki> -o nix-install.sh}}, view it: {{ic|less ./nix-install.sh}}, and run the script {{ic|sh ./nix-install.sh install}} to start the installation. | |||
{{Warning|Running {{ic|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.}} | |||
{{Note|The installer [https://github.com/DeterminateSystems/nix-installer#diagnostics sends telemetry to Determinate Systems by default]. To disable it manually, use {{ic|sh ./nix-install.sh install --diagnostic-endpoint{{=}}""}}.}} | |||
For more information see the manual from [https://zero-to-nix.com/start Determinate Systems]. | |||
== Configuration == | == Configuration == | ||
Line 22: | Line 31: | ||
To have the Nix daemon launched at boot time, [[enable]] {{ic|nix-daemon.service}}. | To have the Nix daemon launched at boot time, [[enable]] {{ic|nix-daemon.service}}. | ||
Add required users to the {{ic|nix-users}} [[user group|group]] in order to access the daemon socket. | Add required users to the {{ic|nix-users}} [[user group|group]] in order to access the daemon socket. Restart your session for the change to have an effect. | ||
Add a channel and update it. | Add a [https://nixos.wiki/wiki/Nix_channels channel] and update it. | ||
$ nix-channel --add <nowiki>https://nixos.org/channels/nixpkgs-unstable</nowiki> | $ nix-channel --add <nowiki>https://nixos.org/channels/nixpkgs-unstable</nowiki> | ||
$ nix-channel --update | $ nix-channel --update | ||
== | == Usage == | ||
{{Note|If you installed Nix from the [[#Native|official repositories]], you must add the {{ic|~/.nix-profile/bin}} directory to your PATH manually.}} | |||
With the shell configured, the following should install ''hello'' into your updated PATH: | |||
$ nix-env -iA nixpkgs.hello | $ nix-env -iA nixpkgs.hello | ||
Run {{ic|hello}} and make sure it is in the right PATH. If it works, you can remove it | The binary itself will be located at {{ic|/nix/store/[hash]-hello-[version]/bin/hello}}. | ||
Run {{ic|hello}} and make sure it is in the right PATH. If it works, you can remove it: | |||
$ nix-env --uninstall hello | $ nix-env --uninstall hello | ||
Or you can check the list of installed | Or you can check the list of installed programs: | ||
$ nix-env - | $ nix-env --query | ||
You can also | You can also list generations: | ||
$ nix-env --list-generations | $ nix-env --list-generations | ||
See {{man|1|nix-env}} for more detailed information. | |||
== Tips and tricks == | |||
=== Max jobs === | === Max jobs === | ||
Line 59: | Line 72: | ||
}} | }} | ||
== | === Graphical acceleration === | ||
To run OpenGL and Vulkan applications, use [https://github.com/guibou/nixGL NixGL]. | |||
=== Desktop integration === | |||
For integrating Nix applications with your desktop environment, add the {{ic|~/.nix-profile/share}} directory to your {{ic|$XDG_DATA_DIRS}}, for instance using {{ic|1=export XDG_DATA_DIRS=$HOME/.nix-profile/share:$XDG_DATA_DIRS}}. | |||
=== Zsh integration for nix-shell === | |||
{{ic|nix-shell}} starts [[Bash]] by default. {{AUR|zsh-nix-shell}} lets you use [[Zsh]] as the default shell in a {{ic|nix-shell}} environment. Some prompt plugins such as {{AUR|zsh-theme-powerlevel10k}} and {{AUR|zsh-pure-prompt}} provide a {{ic|nix-shell}} indicator. | |||
== | == Command completion == | ||
=== Zsh === | |||
{{AUR|nix-zsh-completions}} provides Zsh completions for nix commands such as {{ic|nix-env}} and {{ic|nix-shell}}. | |||
== Troubleshooting == | |||
=== Too many open files === | === Too many open files === | ||
Some builds may run into an error such as | Some builds may run into an error such as: | ||
error: opening directory '/nix/store/...': Too many open files | error: opening directory '/nix/store/...': Too many open files | ||
[[Edit]] {{ic|nix-daemon.service}} and increase the file limit | [[Edit]] {{ic|nix-daemon.service}} and increase the file limit: | ||
[Service] | [Service] | ||
Line 81: | Line 104: | ||
=== Warning message about root user channels === | === Warning message about root user channels === | ||
If you get this error while using Nix: | |||
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring | warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring | ||
The root user will need to update their channels: | |||
# nix-channel --update | # nix-channel --update | ||
=== User-related Nix search path entry does not exist, ignoring === | |||
warning: Nix search path entry '/nix/var/nix/profiles/per-user/<USER>/channels' does not exist, ignoring | |||
See {{Bug|78828}}. Alternatively, you can use the [[#Upstream installation script]] or [[#Zero to Nix installation script]], which do not exhibit the issue. | |||
=== error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I) === | |||
See {{Bug|78828}}. Alternatively, you can use the [[#Upstream installation script]] or [[#Zero to Nix installation script]], which do not exhibit the issue. | |||
=== Sandbox build issues === | === Sandbox build issues === | ||
Line 105: | Line 140: | ||
{{Warning|It is generally not recommended to disable sandboxing as it pollutes the build environment and could possibly cause more build errors. Anything from {{ic|nixpkgs}} expects to be built with the sandbox on.}} | {{Warning|It is generally not recommended to disable sandboxing as it pollutes the build environment and could possibly cause more build errors. Anything from {{ic|nixpkgs}} expects to be built with the sandbox on.}} | ||
The most common fix is to disable sandboxing in the configuration file | The most common fix is to disable sandboxing in the configuration file: | ||
{{hc|/etc/nix/nix.conf|2= | {{hc|/etc/nix/nix.conf|2= | ||
Line 111: | Line 146: | ||
sandbox = false | sandbox = false | ||
}} | }} | ||
Then [[restart]] the {{ic|nix-daemon}} service. | |||
=== Locale warnings === | |||
The [https://nixos.wiki/wiki/Locales Nix wiki] recommends running {{ic|1=export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive}}. Alternatively, export the environment variable {{ic|1=LC_ALL=C}}. | |||
== See also == | == See also == | ||
Line 118: | Line 159: | ||
* [https://nixos.org/nix/manual/ Nix Package Manager Guide] | * [https://nixos.org/nix/manual/ Nix Package Manager Guide] | ||
* [[Wikipedia:Nix package manager]] | * [[Wikipedia:Nix package manager]] | ||
* [https://zero-to-nix.com/ Zero to Nix] |
Latest revision as of 07:35, 23 March 2024
Nix is a purely functional package manager that aims to make package management reliable and reproducible.
Installation
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.
Native
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.
Configuration
To have the Nix daemon launched at boot time, enable nix-daemon.service
.
Add required users to the nix-users
group in order to access the daemon socket. Restart your session for the change to have an effect.
Add a channel and update it.
$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable $ nix-channel --update
Usage
~/.nix-profile/bin
directory to your PATH manually.With the shell configured, the following should install hello into your updated PATH:
$ nix-env -iA nixpkgs.hello
The binary itself will be located at /nix/store/[hash]-hello-[version]/bin/hello
.
Run hello
and make sure it is in the right PATH. If it works, you can remove it:
$ nix-env --uninstall hello
Or you can check the list of installed programs:
$ nix-env --query
You can also list generations:
$ nix-env --list-generations
See nix-env(1) for more detailed information.
Tips and tricks
Max jobs
By default, nix only uses one builder. The following will allow nix to use as many jobs as the number of CPUs:
/etc/nix/nix.conf
max-jobs = auto
Graphical acceleration
To run OpenGL and Vulkan applications, use NixGL.
Desktop integration
For integrating Nix applications with your desktop environment, add the ~/.nix-profile/share
directory to your $XDG_DATA_DIRS
, for instance using export XDG_DATA_DIRS=$HOME/.nix-profile/share:$XDG_DATA_DIRS
.
Zsh integration for nix-shell
nix-shell
starts Bash by default. zsh-nix-shellAUR lets you use Zsh as the default shell in a nix-shell
environment. Some prompt plugins such as zsh-theme-powerlevel10kAUR and zsh-pure-promptAUR provide a nix-shell
indicator.
Command completion
Zsh
nix-zsh-completionsAUR provides Zsh completions for nix commands such as nix-env
and nix-shell
.
Troubleshooting
Too many open files
Some builds may run into an error such as:
error: opening directory '/nix/store/...': Too many open files
Edit nix-daemon.service
and increase the file limit:
[Service] LimitNOFILE=65536
Warning message about root user channels
If you get this error while using Nix:
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
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
See FS#78828. Alternatively, you can use the #Upstream installation script or #Zero to Nix installation script, which do not exhibit the issue.
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
See FS#78828. Alternatively, you can use the #Upstream installation script or #Zero to Nix installation script, which do not exhibit the issue.
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'
The issue is known upstream: #2311, #3000, and #4636.
nixpkgs
expects to be built with the sandbox on.The most common fix is to disable sandboxing in the configuration file:
/etc/nix/nix.conf
# disable sandboxing sandbox = false
Then restart the nix-daemon
service.
Locale warnings
The Nix wiki recommends running export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive
. Alternatively, export the environment variable LC_ALL=C
.