NixOS/en: Difference between revisions

FuzzyBot (talk | contribs)
Updating to match new version of source page
FuzzyBot (talk | contribs)
Updating to match new version of source page
Tags: Mobile edit Mobile web edit
 
Line 3: Line 3:
{{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=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.}}


[https://nixos.org/ NixOS] is a Linux distribution based on the [[Special:MyLanguage/Nix|Nix]] package manager and build system. It supports [https://en.wikipedia.org/wiki/Declarative_programming declarative] system-wide [https://en.wikipedia.org/wiki/Configuration_management configuration management] as well as [https://en.wikipedia.org/wiki/Atomicity_(database_systems) atomic] upgrades and rollbacks, although it can additionally support [https://en.wikipedia.org/wiki/Imperative_programming imperative] package and user management. In NixOS, all components of the distribution — including the [https://en.wikipedia.org/wiki/Linux_kernel kernel], installed [https://en.wikipedia.org/wiki/Package_manager packages] and system configuration files — are built by [[Special:MyLanguage/Nix|Nix]] from [[Wikipedia:Pure function|pure functions]] called [[Special:MyLanguage/Nix Expression Language|Nix expressions]].
[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]].


Since Nix uses [https://en.wikipedia.org/wiki/Executable binary] caching, this provides a unique compromise between the binary-oriented approach used by distributions such as Debian and the [https://en.wikipedia.org/wiki/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.
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.


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 [https://en.wikipedia.org/wiki/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]].
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 ==
== Installation ==
Line 37: Line 37:


{{Main|NixOS on ARM}}
{{Main|NixOS on ARM}}
NixOS isn't officially supported on ARM32 devices (e.g. <code>armv6</code> and <code>armv7l</code>), however, for some of these devices, there may be community support.
NixOS isn't officially supported on ARM32 devices (e.g. <code>armv6</code> and <code>armv7l</code>), however, for some of these devices, there may be community support.


Line 42: Line 43:


{{Main|NixOS on ARM}}
{{Main|NixOS on ARM}}
As long as a device supports the generic systemd boot process, NixOS should run out of the box. However, specific devices with proprietary bootloaders may have issues running it.
As long as a device supports the generic systemd boot process, NixOS should run out of the box. However, specific devices with proprietary bootloaders may have issues running it.


Line 47: Line 49:


{{Main|NixOS on MIPS}}
{{Main|NixOS on MIPS}}
There used to be limited support for MIPS architectures in NixOS, and remnants of this support may still be found in Nixpkgs. However, there is no official support.
There used to be limited support for MIPS architectures in NixOS, and remnants of this support may still be found in Nixpkgs. However, there is no official support.


Line 52: Line 55:


{{Main|RISC-V}}
{{Main|RISC-V}}


NixOS does not provide official support for RISC-V devices. However, several devices may benefit from community support.
NixOS does not provide official support for RISC-V devices. However, several devices may benefit from community support.
Line 58: Line 62:


<span id="declarative-configuration"></span>
<span id="declarative-configuration"></span>
=== Declarative Configuration ===
=== Declarative Configuration ===


Line 82: Line 87:
When using channels, your system or [[Special:MyLanguage/User Environment|user environment]] pulls package definitions and options from a URL pointing to a specific snapshot of the Nix Packages collection (Nixpkgs) and associated NixOS modules.
When using channels, your system or [[Special:MyLanguage/User Environment|user environment]] pulls package definitions and options from a URL pointing to a specific snapshot of the Nix Packages collection (Nixpkgs) and associated NixOS modules.


For more information on using and configuring nix channels, refer to [[Special:MyLanguage/channel branches|channel branches]].
For more information on using and configuring nix channels, refer to [[Special:MyLanguage/Channel branches|channel branches]].


== Internals ==
== Internals ==
Line 90: Line 95:
''Main Article: [[Special:MyLanguage/Nix vs. Linux Standard Base|Nix vs. Linux Standard Base]]''
''Main Article: [[Special:MyLanguage/Nix vs. Linux Standard Base|Nix vs. Linux Standard Base]]''


The main difference between NixOS and other Linux distributions 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 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>).
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>).


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 ===
=== Usage of the Nix store ===
Line 116: Line 121:
}
}
</nowiki>}}
</nowiki>}}
{{file|/etc/nixos/basic-webserver.nix|nix|<nowiki>
{{file|/etc/nixos/basic-webserver.nix|nix|<nowiki>
{
{
Line 124: Line 130:
}
}
</nowiki>}}
</nowiki>}}
{{file|/etc/nixos/blog.nix|nix|<nowiki>
{{file|/etc/nixos/blog.nix|nix|<nowiki>
{
{
Line 132: Line 139:
</nowiki>}}
</nowiki>}}


See the [https://nixos.org/nixos/manual/index.html#sec-writing-modules Modules section of the NixOS Manual] for more details.
See the [https://nixos.org/manual/nixos/stable/index.html#sec-writing-modules Modules section of the NixOS Manual] for more details.


=== Generations ===
=== Generations ===
Line 140: Line 147:
You can roll back via:
You can roll back via:


<syntaxHighlight lang=shell>
<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 147: Line 154:
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


<syntaxHighlight lang=shell>
<syntaxHighlight lang=console>
$ /run/current-system/bin/switch-to-configuration boot
$ /run/current-system/bin/switch-to-configuration boot
</syntaxHighlight>
</syntaxHighlight>
Line 153: Line 160:
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:


<syntaxHighlight lang=shell>
<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


# 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>


List generations:
List generations:
<syntaxHighlight lang=shell>
 
# 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>


Switch generations:
Switch generations:
<syntaxHighlight lang=shell>
 
# 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>


delete broken generation(s):
delete broken generation(s):
<syntaxHighlight lang=shell>
 
# 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>
Line 185: Line 195:
* [[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 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|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.


[[Category:Pedias]]
[[Category:Pedias]]
[[Category:NixOS]]
[[Category:NixOS]]
[[Category:Nix{{#translation:}}]]
[[Category:Nix]]