NixOS: Difference between revisions

imported>HLandau
imported>HLandau
Line 164: Line 164:
''See also: [[Nix vs. Linux Standard Base]]''
''See also: [[Nix vs. Linux Standard Base]]''


The main difference between to Linux Distribution is that NixOS does not follow the [https://en.wikipedia.org/wiki/Linux_Standard_Base Linux Standard Base] file system structure. On LSB-compliant systems software is stored under ''/{,usr}/{bin,lib,share}'' and configuration is generally stored in ''/etc'' .
The main difference between to Linux Distribution is that NixOS does not follow the [https://en.wikipedia.org/wiki/Linux_Standard_Base Linux Standard Base] file system structure. On LSB-compliant systems software is stored under <code>/{,usr}/{bin,lib,share}</code> and configuration is generally stored in <code>/etc</code>.


Software binaries become available for the user environment if they are placed in the bin folder of the LSB. When software is compiled with dynamic library links it will look up the required libraries in the LSB folders ( ''/usr/lib'' ) and load it.
Software binaries are available in the user environment if they are placed in one of the LSB's <code>bin</code> directories. When a program references dynamic libraries it will search for the required libraries in the LSB folders (<code>/lib</code>, <code>/usr/lib</code>).


In NixOS however this structure is not in place. Instead, user environments are essentially a number of symbolic links to all required packages and auxiliary files. These environments are stored in ''nix/var/nix/profiles'' . Each user maintains its own environment.
In NixOS however <code>/lib</code> and <code>/usr/lib</code> do not exist. Instead all system libraries, binaries, kernels, firmware and configuration files are stored beneath <code>/nix/store</code>. The files and directories in <code>/nix/store</code> are named by hashes of the information describing the built data. All of the files and directories placed in the Nix store are immutable.
The booted system profile is stored in a similar fashion but also contains the kernel, firmware, configuration and startup files.


Because there is no standard library folder, all packages will be compiled with explicit paths to the libraries it requires. The nix package manager will ensure that the referenced paths are available in the store. The explicit pinning of library versions makes a reproducible Operating System achievable.
<code>/bin</code> and <code>/usr/bin</code> are almost absent: they contain only <code>/bin/sh</code> and <code>/usr/bin/env</code> respectively, to provide minimal compatibility with existing scripts using shebang lines.


All generated binaries, libraries and configuration is stored in the read-only /nix/store path.
Structuring the system in this way is how NixOS obtains its key advantages over conventional Linux distributions, such as atomicity and rollback support. Every item inside the store is the product of the evaluation of a pure function in Nix called a ''derivation'' (essentially a build). Essentially, the store is the reification of the pure, functional description of the system, which is consumed by Nix and used to generate the contents of the store.
 
User-level environments are implemented using a large number of symbolic links to all required packages and auxiliary files. These environments are stored in <code>/nix/var/nix/profiles</code>. Each user has their own environment.


=== Usage of the Nix Store ===
=== Usage of the Nix Store ===