NixOS: Difference between revisions
imported>Makefu →Modules: init |
imported>Makefu No edit summary |
||
Line 185: | Line 185: | ||
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. | 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. | ||
NixOS modules implement a typing system which allows type validation and merging of module options which are defined in multiple places. | 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: | ||
<code>configuration.nix</code> | |||
<syntaxHighlight lang=nix> | |||
{ | |||
imports = [ | |||
./basic-webserver.nix | |||
./blog.nix | |||
]; | |||
} | |||
</syntaxHighlight> | |||
<code>basic-webserver.nix</code>: | |||
<syntaxHighlight lang=nix> | |||
{ | |||
services.nginx.enable = true; | |||
services.nginx.virtualHosts."example.com" = { | |||
root = "/var/www/example.com"; | |||
}; | |||
} | |||
</syntaxHighlight> | |||
<code>blog.nix</code> | |||
<syntaxHighlight lang=nix> | |||
{ | |||
services.nginx.virtualHosts."blog.example.com" = { | |||
root = "/var/www/blog.example.com"; | |||
}; | |||
} | |||
</syntaxHighlight> | |||
see also: [https://nixos.org/nixos/manual/index.html#sec-writing-modules NixOS Manual about writing Modules] | see also: [https://nixos.org/nixos/manual/index.html#sec-writing-modules NixOS Manual about writing Modules] |