at 23.05-pre 2.4 kB view raw
1<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-replace-modules"> 2 <title>Replace Modules</title> 3 <para> 4 Modules that are imported can also be disabled. The option 5 declarations, config implementation and the imports of a disabled 6 module will be ignored, allowing another to take it's place. This 7 can be used to import a set of modules from another channel while 8 keeping the rest of the system on a stable release. 9 </para> 10 <para> 11 <literal>disabledModules</literal> is a top level attribute like 12 <literal>imports</literal>, <literal>options</literal> and 13 <literal>config</literal>. It contains a list of modules that will 14 be disabled. This can either be the full path to the module or a 15 string with the filename relative to the modules path (eg. 16 &lt;nixpkgs/nixos/modules&gt; for nixos). 17 </para> 18 <para> 19 This example will replace the existing postgresql module with the 20 version defined in the nixos-unstable channel while keeping the rest 21 of the modules and packages from the original nixos channel. This 22 only overrides the module definition, this won't use postgresql from 23 nixos-unstable unless explicitly configured to do so. 24 </para> 25 <programlisting language="bash"> 26{ config, lib, pkgs, ... }: 27 28{ 29 disabledModules = [ &quot;services/databases/postgresql.nix&quot; ]; 30 31 imports = 32 [ # Use postgresql service from nixos-unstable channel. 33 # sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable 34 &lt;nixos-unstable/nixos/modules/services/databases/postgresql.nix&gt; 35 ]; 36 37 services.postgresql.enable = true; 38} 39</programlisting> 40 <para> 41 This example shows how to define a custom module as a replacement 42 for an existing module. Importing this module will disable the 43 original module without having to know it's implementation details. 44 </para> 45 <programlisting language="bash"> 46{ config, lib, pkgs, ... }: 47 48with lib; 49 50let 51 cfg = config.programs.man; 52in 53 54{ 55 disabledModules = [ &quot;services/programs/man.nix&quot; ]; 56 57 options = { 58 programs.man.enable = mkOption { 59 type = types.bool; 60 default = true; 61 description = &quot;Whether to enable manual pages.&quot;; 62 }; 63 }; 64 65 config = mkIf cfg.enabled { 66 warnings = [ &quot;disabled manpages for production deployments.&quot; ]; 67 }; 68} 69</programlisting> 70</section>