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