NixOS: Difference between revisions

imported>HLandau
No edit summary
imported>HLandau
adjust Declarative Configuration section
Line 30: Line 30:
=== Declarative Configuration ===
=== Declarative Configuration ===


One of NixOS's most distinguishing features is the ability to ''declaratively configure'' the whole system. This is done by specifying a configuration file which defines which packages are installed on the system, which services to run and various other settings and options. This file is normally called <code>configuration.nix</code> and is found by default at <code>/etc/nixos</code>, although another location can be set using the environment variable <code>NIX_PATH</code>. The system configuration is then built with the command <code>nixos-rebuild</code>. The following is an example of a <code>configuration.nix</code> file:
One of NixOS's most distinguishing features is the ability to ''declaratively configure'' the whole system. This is done by specifying a configuration file which specifies the entire system state, including which packages should be installed and all the various system settings and options. This configuration file is normally located at <code>/etc/nixos/configuration.nix</code> (although another location may be specified using the environment variable <code>NIX_PATH</code>); after the configuration file is modified, the new configuration is then made active by running <code>nixos-rebuild switch</code>. The switch is atomic and can be rolled back if necessary. The configuration files under <code>/etc/nixos</code> may even be kept in a version control system such as Git if desired.
 
Conventional distributions require users to manually modify configuration files, but these changes are not tracked. If distributions change the default contents of configuration files, these changes often have to be manually merged by users if they have previously modified the file, or the distribution modifications may not be integrated at all, leading to undesired configuration drift. Configuration settings and changes are rarely recorded in a version control system. These shortcomings are often rectified after-the-fact if at all by configuration management solutions such as Puppet or Chef. These tools reconcile system configuration with a description of the expected state. However, these tools are not integrated into the operating system design and are simply layered on top, and OS configuration may still vary where an aspect of OS configuration has not been specified in the description of expected state.
 
By comparison, NixOS's declarative configuration system provides a fully integrated facility for OS configuration management. Failure to specify any given item of configuration results in that item having a well-defined state, rather than being allowed to drift unmonitored. Because the full system configuration is captured in the NixOS configuration system, this also makes NixOS highly suited to the automatic deployment of configuration in environments such as automated server farms; tools such as [NixOps] make this easy.
 
The following is an example <code>/etc/nixos/configuration.nix</code>:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">