NixOS: Difference between revisions

imported>HLandau
imported>HLandau
Line 182: Line 182:


=== Modules ===
=== Modules ===
The NixOS module system as defined in  [[Nixpkgs]] provides the means necessary to customize the configuration of the Operating System. It is used to enable and customize services such as '''nginx''', enable firmware and customize the kernel.


All module-configuration is generally performed by adding the option entries into your '''configuration.nix'''. Most samples in the wiki are generally about the customization of the operating system and therefore require you to add the said options to you configuration file.
''See also: [https://nixos.org/nixos/manual/index.html#sec-writing-modules Modules (NixOS Manual)]''


NixOS modules implement a typing system which allows type validation and merging of module options which are defined in multiple places. By that you could import multiple files and update options in multiple locations:
The NixOS module system as defined in  [[Nixpkgs]] provides the means necessary to customize the configuration of the OS. It is used to enable and customize services such as nginx, enable firmware and customize the kernel.
 
All module configuration is generally performed by adding options to <code>/etc/nixos/configuration.nix</code>. Most of the examples in the wiki show how this file can be used to configure the OS.
 
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>configuration.nix</code>
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
# /etc/nixos/configuration.nix
{
{
   imports = [
   imports = [
Line 197: Line 200:
}
}
</syntaxHighlight>
</syntaxHighlight>
<code>basic-webserver.nix</code>:
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
# /etc/nixos/basic-webserver.nix
{
{
   services.nginx.enable = true;
   services.nginx.enable = true;
Line 206: Line 209:
}
}
</syntaxHighlight>
</syntaxHighlight>
<code>blog.nix</code>
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
# /etc/nixos/blog.nix
{
{
   services.nginx.virtualHosts."blog.example.com" = {
   services.nginx.virtualHosts."blog.example.com" = {
Line 214: Line 217:
}
}
</syntaxHighlight>
</syntaxHighlight>
see also: [https://nixos.org/nixos/manual/index.html#sec-writing-modules NixOS Manual about writing Modules]


=== Generations ===
=== Generations ===