NixOS modules: Difference between revisions
imported>Ixxie m Ixxie moved page NixOS:Modules to NixOS Modules: Stylistic improvement of title. |
imported>Tv talk about module option incompatibilities |
||
Line 75: | Line 75: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Compatibility Issues with Different Nixpkgs Versions == | |||
Module options between Nixpkgs revisions can sometimes change in incompatible ways. | |||
For example, the option <code>services.nginx.virtualHosts.*.port</code> in nixpkgs-17.03 was replaced by <code>services.nginx.virtualHosts.*.listen</code> in nixpkgs-17.09. If configuration.nix has to accommodate both variants, <code>options</code> can be inspected: | |||
<syntaxhighlight lang="nix"> | |||
{ options, ... }: { | |||
services.nginx.virtualHosts.somehost = { /* common configuration */ } | |||
// (if builtins.hasAttr "port" (builtins.head options.services.nginx.virtualHosts.type.getSubModules).submodule.option | |||
then { port = 8000; } | |||
else { listen = [ { addr = "0.0.0.0"; port = 8000; } ]; }); | |||
} | |||
</syntaxhighlight> | |||
== References == | == References == |