NixOS: Difference between revisions
No edit summary |
m use "console" as syntax highlighting language for shell commands (Note: comments that start at beginnig of line aren't highlighted as comments, it's aka superuser sign. The use of `sudo cmd` vs `# cmd` across the wiki is inconsistent and `#` being used for comments is definitely more common. Can we somehow tweak the <syntaxhighlight> to treat `#` as comment and ask editors to use `sudo` to mark privilege escalation?) |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 6: | Line 6: | ||
<!--T:2--> | <!--T:2--> | ||
[https://nixos.org/ NixOS] is a Linux distribution based on the [[Special:MyLanguage/Nix|Nix]] package manager and build system. It supports [ | [https://nixos.org/ NixOS] is a Linux distribution based on the [[Special:MyLanguage/Nix|Nix]] package manager and build system. It supports [[Wikipedia:Declarative programming|declarative]] system-wide [[Wikipedia:Configuration management|configuration management]] as well as [[Wikipedia:Atomicity (database_systems)|atomic]] upgrades and rollbacks, although it can additionally support [[Wikipedia:Imperative programming|imperative]] package and user management. In NixOS, all components of the distribution — including the [[Wikipedia:Linux kernel|kernel]], installed [[Wikipedia:Package manager|packages]] and system configuration files — are built by [[Special:MyLanguage/Nix|Nix]] from [[Wikipedia:Pure function|pure functions]] called [[Special:MyLanguage/Nix (language)|Nix expressions]]. | ||
<!--T:3--> | <!--T:3--> | ||
Since Nix uses [ | Since Nix uses [[Wikipedia:Executable|binary]] caching, this provides a unique compromise between the binary-oriented approach used by distributions such as Debian and the [[Wikipedia:Source code|source]]-oriented approach used by distributions such as Gentoo. Binaries can be used for standard components, and custom-built packages and modules can be used automatically when a pre-built binary is not available. | ||
<!--T:4--> | <!--T:4--> | ||
Stable NixOS releases are delivered twice a year (around the end of May and the end of November). NixOS was created by [https://edolstra.github.io/ Eelco Dolstra] and [ | Stable NixOS releases are delivered twice a year (around the end of May and the end of November). NixOS was created by [https://edolstra.github.io/ Eelco Dolstra] and [[Wikipedia:Armijn Hemel|Armijn Hemel]], and initially released in 2003. It is community developed and maintained under the stewardship of the [[Special:MyLanguage/Nix_Community#NixOS_Foundation|NixOS Foundation]]. | ||
== Installation == <!--T:5--> | == Installation == <!--T:5--> | ||
| Line 118: | Line 118: | ||
<!--T:36--> | <!--T:36--> | ||
For more information on using and configuring nix channels, refer to [[Special:MyLanguage/ | For more information on using and configuring nix channels, refer to [[Special:MyLanguage/Channel branches|channel branches]]. | ||
== Internals == <!--T:37--> | == Internals == <!--T:37--> | ||
| Line 128: | Line 128: | ||
<!--T:40--> | <!--T:40--> | ||
The main difference between NixOS and other Linux distributions is that NixOS does not follow the [ | The main difference between NixOS and other Linux distributions is that NixOS does not follow the [[Wikipedia: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 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>). | ||
<!--T:41--> | <!--T:41--> | ||
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 placed in the [[Special:MyLanguage/Nix#Nix store|Nix store]]. 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. <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. User-level environments are implemented using a large number of symbolic links to all required packages and auxiliary files. These environments are called [[Special:MyLanguage/Nix#Profiles|profiles]] and are stored in <code>/nix/var/nix/profiles</code>, each user having their own profiles. Structuring the system in this way is how NixOS obtains its key advantages over conventional Linux distributions, such as atomicity and rollback support. | 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 placed in the [[Special:MyLanguage/Nix (package_manager)#Nix store|Nix store]]. 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. <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. User-level environments are implemented using a large number of symbolic links to all required packages and auxiliary files. These environments are called [[Special:MyLanguage/Nix#Profiles|profiles]] and are stored in <code>/nix/var/nix/profiles</code>, each user having their own profiles. Structuring the system in this way is how NixOS obtains its key advantages over conventional Linux distributions, such as atomicity and rollback support. | ||
=== Usage of the Nix store === <!--T:42--> | === Usage of the Nix store === <!--T:42--> | ||
| Line 179: | Line 179: | ||
<!--T:49--> | <!--T:49--> | ||
See the [https://nixos.org/nixos/ | See the [https://nixos.org/manual/nixos/stable/index.html#sec-writing-modules Modules section of the NixOS Manual] for more details. | ||
=== Generations === <!--T:50--> | === Generations === <!--T:50--> | ||
| Line 190: | Line 190: | ||
<!--T:53--> | <!--T:53--> | ||
<syntaxHighlight lang= | <syntaxHighlight lang=console> | ||
$ nix-env --rollback # roll back a user environment | $ nix-env --rollback # roll back a user environment | ||
$ nixos-rebuild switch --rollback # roll back a system environment | $ nixos-rebuild switch --rollback # roll back a system environment | ||
| Line 199: | Line 199: | ||
</translate> | </translate> | ||
<syntaxHighlight lang= | <syntaxHighlight lang=console> | ||
$ /run/current-system/bin/switch-to-configuration boot | $ /run/current-system/bin/switch-to-configuration boot | ||
</syntaxHighlight> | </syntaxHighlight> | ||
| Line 208: | Line 208: | ||
<!--T:56--> | <!--T:56--> | ||
<syntaxHighlight lang= | <syntaxHighlight lang=console> | ||
# delete generations older than 30 days | $ # delete generations older than 30 days | ||
$ nix-collect-garbage --delete-older-than 30d | $ nix-collect-garbage --delete-older-than 30d | ||
<!--T:57--> | <!--T:57--> | ||
# delete ALL previous generations - you can no longer rollback after running this | $ # delete ALL previous generations - you can no longer rollback after running this | ||
$ nix-collect-garbage -d | $ nix-collect-garbage -d | ||
</syntaxHighlight> | </syntaxHighlight> | ||
| Line 219: | Line 219: | ||
<!--T:58--> | <!--T:58--> | ||
List generations: | List generations: | ||
<syntaxHighlight lang= | <syntaxHighlight lang=console> | ||
# as root | $ # as root | ||
$ nix-env --list-generations --profile /nix/var/nix/profiles/system | $ nix-env --list-generations --profile /nix/var/nix/profiles/system | ||
</syntaxHighlight> | </syntaxHighlight> | ||
| Line 226: | Line 226: | ||
<!--T:59--> | <!--T:59--> | ||
Switch generations: | Switch generations: | ||
<syntaxHighlight lang= | <syntaxHighlight lang=console> | ||
# as root switch to generation 204 | $ # as root switch to generation 204 | ||
$ nix-env --profile /nix/var/nix/profiles/system --switch-generation 204 | $ nix-env --profile /nix/var/nix/profiles/system --switch-generation 204 | ||
</syntaxHighlight> | </syntaxHighlight> | ||
| Line 233: | Line 233: | ||
<!--T:60--> | <!--T:60--> | ||
delete broken generation(s): | delete broken generation(s): | ||
<syntaxHighlight lang= | <syntaxHighlight lang=console> | ||
# as root delete broken generations 205 and 206 | $ # as root delete broken generations 205 and 206 | ||
$ nix-env --profile /nix/var/nix/profiles/system --delete-generations 205 206 | $ nix-env --profile /nix/var/nix/profiles/system --delete-generations 205 206 | ||
</syntaxHighlight> | </syntaxHighlight> | ||
| Line 244: | Line 244: | ||
<!--T:63--> | <!--T:63--> | ||
* [[Special:MyLanguage/NixOS modules| | * [[Special:MyLanguage/NixOS modules|NixOS modules]], a library for modular [[Special:MyLanguage/Overview of the Nix Expression Language#Expressions|Nix expressions]] which powers [[#declarative-configuration|the declarative configuration of NixOS]]. | ||
* [[Special:MyLanguage/NixOS VM tests| | * [[Special:MyLanguage/NixOS VM tests|NixOS VM tests]], a library for creating reproducible infrastructure tests, based on [[Special:MyLanguage/Nixpkgs|Nixpkgs]], [[Special:MyLanguage/NixOS|NixOS]], QEMU and Perl. | ||
* [https://github.com/ryan4yin/nixos-and-flakes-book NixOS & Flakes Book] (Ryan4yin, 2023) - 🛠️ ❤️ | * [https://github.com/ryan4yin/nixos-and-flakes-book NixOS & Flakes Book] (Ryan4yin, 2023) - 🛠️ ❤️ An unofficial NixOS & Flakes book for beginners. | ||
</translate> | </translate> | ||