Nix (package manager): Difference between revisions

Sdht0 (talk | contribs)
Configuration: Copy edit
Roxwize (talk | contribs)
Marked this version for translation
 
(16 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<translate>
{{Navbox Nix}}
<!--T:1-->
{{Disambiguation|message=<translate><!--T:35--> This article is about the Nix package manager. Not to be confused with the [[<tvar name="1">Nix ecosystem</tvar>|Nix ecosystem]], the [[<tvar name="2">Nix (language)</tvar>|Nix language]] or the [[<tvar name="3">Nix (command)</tvar>|Nix command]].</translate>}}
Nix is a package manager and build system that parses reproducible build instructions specified in the [[Nix Expression Language]], a pure functional language with lazy evaluation. Nix expressions are pure functions<ref>Values cannot change during computation. Functions always produce the same output if their input does not change. </ref>taking dependencies as arguments and producing a ''[[Derivations|derivation]]'' specifying a reproducible build environment for the package. Nix stores the results of the build in unique addresses specified by a hash of the complete dependency tree, creating an immutable package store (aka the [[#Nix store|nix store]]) that allows for atomic upgrades, rollbacks and concurrent installation of different versions of a package, essentially eliminating [https://en.wikipedia.org/wiki/Dependency_hell dependency hell].  
 
<translate><!--T:1-->
Nix is a package manager and build system that parses reproducible build instructions specified in the [[<tvar name="1">Nix (language)</tvar>|Nix Expression Language]], a pure functional language with lazy evaluation. Nix expressions are pure functions<ref>Values cannot change during computation. Functions always produce the same output if their input does not change.</ref> taking dependencies as arguments and producing a ''[[<tvar name="2">Derivations</tvar>|derivation]]'' specifying a reproducible build environment for the package. Nix stores the results of the build in unique addresses specified by a hash of the complete dependency tree, creating an immutable package store (aka the [[#Nix store|nix store]]) that allows for atomic upgrades, rollbacks and concurrent installation of different versions of a package, essentially eliminating [[<tvar name="3">Wikipedia:Dependency hell</tvar>|dependency hell]].


== Usage == <!--T:2-->
== Usage == <!--T:2-->
Line 8: Line 10:
<!--T:3-->
<!--T:3-->
=== Installation ===
=== Installation ===
On NixOS, Nix is automatically installed.
On [[<tvar name="1">NixOS</tvar>|NixOS]], Nix is automatically installed.


<!--T:4-->
<!--T:4-->
On other Linux distributions or on macOS, you can install Nix following the [https://nixos.org/manual/nix/stable/installation/installation installation section of the Nix manual].
On other Linux distributions or on macOS, you can install Nix following the [<tvar name="1">https://nix.dev/manual/nix/stable/installation/</tvar> installation section of the Nix manual].


=== Nix commands === <!--T:5-->
=== Nix commands === <!--T:5-->


<!--T:6-->
<!--T:6-->
The [[Nix command|Nix commands]] are documented in the [https://nixos.org/manual/nix/stable/command-ref/command-ref Nix reference manual]: main commands, utilities and experimental commands. Prior to version 2.0 (released in February 2018) there have been different commands.
The [[<tvar name="1">Nix (command line utilities)</tvar>|Nix commands]] are documented in the [<tvar name="2">https://nix.dev/manual/nix/stable/command-ref/</tvar> Nix reference manual]: main commands, utilities and experimental commands. Prior to version 2.0 (released in February 2018) there have been different commands.


<!--T:7-->
<!--T:7-->
=== Configuration ===
=== Configuration ===
On NixOS, Nix can be configured using the [https://search.nixos.org/options?query=nix. <code>nix</code> option].  
On NixOS, Nix can be configured using the [<tvar name="1">https://search.nixos.org/options?query=nix</tvar> <code>nix</code> option].  


<!--T:8-->
<!--T:8-->
Standalone Nix is configured through <code>nix.conf</code> (usually found in <code>/etc/nix/</code>). Details on the available options are [https://nixos.org/manual/nix/stable/command-ref/conf-file found in the Nix reference manual].  
Standalone Nix is configured through <code>nix.conf</code> (usually found in <code>/etc/nix/</code>). Details on the available options are [<tvar name="1">https://nix.dev/manual/nix/stable/command-ref/conf-file</tvar> found in the Nix reference manual].  


<!--T:9-->
<!--T:9-->
You can also configure Nix using [[Home Manager]], which manages declarative environments for a single user. For system-wide configuration, you can use [https://github.com/numtide/system-manager System Manager] on Linux and [https://github.com/LnL7/nix-darwin nix-darwin] on macOS.
You can also configure Nix using [[<tvar name="1">Home Manager</tvar>|Home Manager]], which manages declarative environments for a single user. For system-wide configuration, you can use [<tvar name="2">https://github.com/numtide/system-manager</tvar> System Manager] on Linux and [<tvar name="3">https://github.com/nix-darwin/nix-darwin</tvar> nix-darwin] on macOS.


== Internals == <!--T:10-->
== Internals == <!--T:10-->
Line 32: Line 34:
=== Nix store === <!--T:11-->
=== Nix store === <!--T:11-->


<!--T:12-->
<!--T:27-->
{{Split|reason=The nix store is conceptually separate enough that it warrants a separate article.}}
 
<!--T:28-->
Packages built by Nix are placed in the read-only ''Nix store'', normally found in <code>/nix/store</code>. Each package is given a unique address specified by a cryptographic hash followed by the package name and version, for example <code>/nix/store/nawl092prjblbhvv16kxxbk6j9gkgcqm-git-2.14.1</code>. These prefixes hash all the inputs to the build process, including the source files, the full dependency tree, compiler flags, etc. This allows Nix to simultaneously install different versions of the same package, and even different builds of the same version, for example variants built with different compilers. When adding, removing or updating a package, nothing is removed from the store; instead, symlinks to these packages are added, removed or changed in ''profiles''.
Packages built by Nix are placed in the read-only ''Nix store'', normally found in <code>/nix/store</code>. Each package is given a unique address specified by a cryptographic hash followed by the package name and version, for example <code>/nix/store/nawl092prjblbhvv16kxxbk6j9gkgcqm-git-2.14.1</code>. These prefixes hash all the inputs to the build process, including the source files, the full dependency tree, compiler flags, etc. This allows Nix to simultaneously install different versions of the same package, and even different builds of the same version, for example variants built with different compilers. When adding, removing or updating a package, nothing is removed from the store; instead, symlinks to these packages are added, removed or changed in ''profiles''.
==== Cleaning the Nix store ==== <!--T:29-->
<!--T:30-->
For information relating to cleaning the Nix store, refer to {{NixOS Manual|name=NixOS Manual: Chapter - Cleaning the Nix Store|anchor=#sec-nix-gc}}.
==== Nix store corruption ==== <!--T:31-->
<!--T:32-->
For information relating to fixing a corrupted Nix store, refer to {{NixOS Manual|name=NixOS Manual: Chapter - Nix Store Corruption|anchor=#sec-nix-store-corruption}}.
==== Valid Nix store names ==== <!--T:33-->
<!--T:34-->
{{main|Valid Nix store path names}}


=== Profiles === <!--T:13-->
=== Profiles === <!--T:13-->
Line 43: Line 63:


<!--T:16-->
<!--T:16-->
When sandbox builds are enabled, Nix will setup an isolated environment for each build process. It is used to remove further hidden dependencies set by the build environment to improve reproducibility. This includes access to the network during the build outside of <code>fetch*</code> functions and files outside the Nix store.  Depending on the operating system access to other resources are blocked as well (ex. inter process communication is isolated on Linux); see [https://nixos.org/nix/manual/#sec-conf-file nix.conf section] in the Nix manual for details.
When sandbox builds are enabled, Nix will setup an isolated environment for each build process. It is used to remove further hidden dependencies set by the build environment to improve reproducibility. This includes access to the network during the build outside of <code>fetch*</code> functions and files outside the Nix store.  Depending on the operating system access to other resources are blocked as well (ex. inter process communication is isolated on Linux).


<!--T:17-->
<!--T:17-->
Sandboxing is enabled by default on Linux, and disabled by default on macOS.
Sandboxing is enabled by default on Linux, and disabled by default on macOS.
In pull requests for [https://github.com/NixOS/nixpkgs/ Nixpkgs] people are asked to test builds with sandboxing enabled (see <code>Tested using sandboxing</code> in the pull request template) because in [https://nixos.org/hydra/ official Hydra builds] sandboxing is also used.
In pull requests for [<tvar name="1">https://github.com/NixOS/nixpkgs/</tvar> Nixpkgs] people are asked to test builds with sandboxing enabled (see <code>Tested using sandboxing</code> in the pull request template) because in [<tvar name="2">https://nixos.org/hydra/</tvar> official Hydra builds] sandboxing is also used.


<!--T:18-->
<!--T:18-->
Line 58: Line 78:


<!--T:21-->
<!--T:21-->
* [https://cs.tvl.fyi/depot/-/tree/tvix tvix]
* [<tvar name="1">https://code.tvl.fyi/tree/tvix</tvar> tvix]


<!--T:22-->
<!--T:22-->
Line 64: Line 84:


<!--T:23-->
<!--T:23-->
* [https://lix.systems/ lix]
* [<tvar name="1">https://lix.systems/</tvar> lix]


<!--T:24-->
<!--T:24-->
Earlier attempts can be found on [https://riir-nix.github.io/ riir-nix]
Earlier attempts can be found on [<tvar name="1">https://riir-nix.github.io/</tvar> riir-nix]


<!--T:25-->
<!--T:25-->