NixOS: Difference between revisions

imported>Samueldr
m Use {{file}} template (first code block only)
imported>Ixxie
m Converted examples in modules section to the file template.
Line 32: Line 32:
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.
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>:
Here is a simple example of a NixOS system configuration:


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
Line 150: Line 150:
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:


<code>/etc/nixos/configuration.nix</code>:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
<syntaxHighlight lang=nix>
{
{
   imports = [
   imports = [
Line 158: Line 157:
   ];
   ];
}
}
</syntaxHighlight>
</nowiki>}}
<code>/etc/nixos/basic-webserver.nix</code>:
{{file|/etc/nixos/basic-webserver.nix|nix|<nowiki>
<syntaxHighlight lang=nix>
{
{
   services.nginx.enable = true;
   services.nginx.enable = true;
Line 167: Line 165:
   };
   };
}
}
</syntaxHighlight>
</nowiki>}}
<code>/etc/nixos/blog.nix</code>:
{{file|etc/nixos/blog.nix|nix|<nowiki>
<syntaxHighlight lang=nix>
{
{
   services.nginx.virtualHosts."blog.example.com" = {
   services.nginx.virtualHosts."blog.example.com" = {
Line 175: Line 172:
   };
   };
}
}
</syntaxHighlight>
</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/nixos/manual/index.html#sec-writing-modules Modules section of the NixOS Manual] for more details.