NixOS: Difference between revisions
No edit summary |
m introduction inaccurately claims NixOS was first released in 2003, whereas it was released in 2013 with the 13.10 release. |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
<languages/> | <languages/> | ||
{{Navbox Nix}} | {{Navbox Nix}} | ||
{{Expansion|reason=It needs to be an easy introduction, because its one of the first articles new users read here. Thats why it needs to be simplified a bit and more complex topics should be moved to other articles.}} | {{Expansion|reason=<translate><!--T:1--> It needs to be an easy introduction, because its one of the first articles new users read here. Thats why it needs to be simplified a bit and more complex topics should be moved to other articles.</translate>}} | ||
<translate> | |||
<!--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 2013<ref>https://nixos.org/blog/announcements/2013/nixos-1310/</ref>. 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 48: | Line 47: | ||
==== 32-bit ARM architectures ==== <!--T:17--> | ==== 32-bit ARM architectures ==== <!--T:17--> | ||
</translate> | |||
{{Main|NixOS on ARM}} | {{Main|NixOS on ARM}} | ||
<translate> | <translate> | ||
<!--T:18--> | <!--T:18--> | ||
| Line 56: | Line 56: | ||
==== 64-bit ARM architectures ==== <!--T:19--> | ==== 64-bit ARM architectures ==== <!--T:19--> | ||
</translate> | |||
{{Main|NixOS on ARM}} | {{Main|NixOS on ARM}} | ||
<translate> | <translate> | ||
<!--T:20--> | <!--T:20--> | ||
| Line 64: | Line 65: | ||
==== MIPS architectures ==== <!--T:21--> | ==== MIPS architectures ==== <!--T:21--> | ||
</translate> | |||
{{Main|NixOS on MIPS}} | {{Main|NixOS on MIPS}} | ||
<translate> | <translate> | ||
<!--T:22--> | <!--T:22--> | ||
| Line 72: | Line 74: | ||
==== RISC-V architectures ==== <!--T:64--> | ==== RISC-V architectures ==== <!--T:64--> | ||
</translate> | |||
{{Main|RISC-V}} | {{Main|RISC-V}} | ||
<translate> | <translate> | ||
| Line 81: | Line 84: | ||
== Usage == <!--T:23--> | == Usage == <!--T:23--> | ||
</translate> | |||
<span id="declarative-configuration"></span> | <span id="declarative-configuration"></span> | ||
<translate> | <translate> | ||
=== Declarative Configuration === <!--T:24--> | === Declarative Configuration === <!--T:24--> | ||
| Line 118: | Line 122: | ||
<!--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 132: | ||
<!--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 151: | Line 155: | ||
<!--T:48--> | <!--T:48--> | ||
The NixOS module system implements a typing system which allows typechecking of option settings. It also enables options defined in multiple places to be merged automatically. This allows you to spread your configuration over multiple files, and the options you set across all of those files will be merged together: | The NixOS module system implements a typing system which allows typechecking of option settings. It also enables options defined in multiple places to be merged automatically. This allows you to spread your configuration over multiple files, and the options you set across all of those files will be merged together: | ||
</translate> | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
{ | { | ||
| Line 161: | Line 165: | ||
} | } | ||
</nowiki>}} | </nowiki>}} | ||
{{file|/etc/nixos/basic-webserver.nix|nix|<nowiki> | {{file|/etc/nixos/basic-webserver.nix|nix|<nowiki> | ||
{ | { | ||
| Line 169: | Line 174: | ||
} | } | ||
</nowiki>}} | </nowiki>}} | ||
{{file|/etc/nixos/blog.nix|nix|<nowiki> | {{file|/etc/nixos/blog.nix|nix|<nowiki> | ||
{ | { | ||
| Line 176: | Line 182: | ||
} | } | ||
</nowiki>}} | </nowiki>}} | ||
<translate> | <translate> | ||
<!--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 188: | Line 194: | ||
<!--T:52--> | <!--T:52--> | ||
You can roll back via: | You can roll back via: | ||
</translate> | |||
<syntaxHighlight lang=console> | |||
<syntaxHighlight lang= | |||
$ 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 | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
<!--T:54--> | <!--T:54--> | ||
NixOS also places entries for previous generations in the bootloader menu, so as a last resort you can always revert to a previous configuration by rebooting. To set the currently booted generation as the default run | NixOS also places entries for previous generations in the bootloader menu, so as a last resort you can always revert to a previous configuration by rebooting. To set the currently booted generation as the default run | ||
</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 206: | Line 213: | ||
<!--T:55--> | <!--T:55--> | ||
Because NixOS keeps previous generations of system state available in case rollback is desired, old package versions aren't deleted from your system immediately after an update. You can delete old generations manually: | Because NixOS keeps previous generations of system state available in case rollback is desired, old package versions aren't deleted from your system immediately after an update. You can delete old generations manually: | ||
</translate> | |||
<syntaxHighlight lang=console> | |||
<syntaxHighlight lang= | $ # 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 | ||
$ # 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> | ||
<translate> | |||
<!--T:58--> | <!--T:58--> | ||
List generations: | List generations: | ||
<syntaxHighlight lang= | </translate> | ||
# as root | |||
<syntaxHighlight lang=console> | |||
$ # as root | |||
$ nix-env --list-generations --profile /nix/var/nix/profiles/system | $ nix-env --list-generations --profile /nix/var/nix/profiles/system | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | |||
<!--T:59--> | <!--T:59--> | ||
Switch generations: | Switch generations: | ||
<syntaxHighlight lang= | </translate> | ||
# as root switch to generation 204 | |||
<syntaxHighlight lang=console> | |||
$ # 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> | ||
<translate> | |||
<!--T:60--> | <!--T:60--> | ||
delete broken generation(s): | delete broken generation(s): | ||
<syntaxHighlight lang= | </translate> | ||
# as root delete broken generations 205 and 206 | |||
<syntaxHighlight lang=console> | |||
$ # 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> | ||
<translate> | |||
<!--T:61--> | <!--T:61--> | ||
You can configure automatic garbage collection by setting the [https://search.nixos.org/options?query=nix.gc nix.gc] options in <code>/etc/nixos/configuration.nix</code>. This is recommended, as it keeps the size of the Nix store down. | You can configure automatic garbage collection by setting the [https://search.nixos.org/options?query=nix.gc nix.gc] options in <code>/etc/nixos/configuration.nix</code>. This is recommended, as it keeps the size of the Nix store down. | ||
| Line 247: | Line 263: | ||
* [[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. | * [[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) - 🛠️ ❤️ An unofficial NixOS & Flakes book for beginners. | * [https://github.com/ryan4yin/nixos-and-flakes-book NixOS & Flakes Book] (Ryan4yin, 2023) - 🛠️ ❤️ An unofficial NixOS & Flakes book for beginners. | ||
</translate> | |||
[[Category:Pedias]] | [[Category:Pedias]] | ||
[[Category:NixOS]] | [[Category:NixOS]] | ||
[[Category:Nix | [[Category:Nix]] | ||