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