NixOS: Difference between revisions

imported>Ixxie
No edit summary
imported>Makefu
No edit summary
Line 159: Line 159:


== Internals ==
== Internals ==
=== Comparsion to traditional Linux Distributions ===
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 .
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 ( <code>usr/lib</code> ) and load it.
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 <code>nix/var/nix/profiles</code> . Each user maintains its own environment.
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.
All generated binaries, libraries and configuration is stored in the read-only /nix/store path.
see also: [[Nix vs. Linux Standard Base]]
=== Usage of the Nix Store ==
A lot of confusion for newcomers arises from the fact that configuration is stored in the read-only nix store along with all the installed packages. This fact makes it impossible to manually edit system configuration, all configuration changes must be performed by editing the **/etc/nixos/configuration.nix** file. NixOS provides the Modules System for editing all required configurations. Users should first check if an option for the configuration they require already exist before manually adding files or configuration via low-level NixOS features like activation scripts.
The system purity makes it possible to share system configuration without the need to edit multiple files. If you provide the same inputs, same version of **nixpkgs** and **configuration.nix** you will get the exact same booted system once deployed.


=== Modules ===
=== Modules ===


=== Generations ===
=== Generations ===
Environments are versioned via generation, every change to an environment will create a new generation. With this structure it is possible to revert changes with the help of the nix package manager. This is also true for the booted system, however a restart is required for changing the kernel.
Rolling back can be done via:
<syntaxHighlight lang=shell>
$ nix-env --rollback # roll back a user environment
$ nixos-rebuild switch --rollback # roll back a system environment
</syntaxHighlight>