1# Replace Modules {#sec-replace-modules} 2 3Modules that are imported can also be disabled. The option declarations, 4config implementation and the imports of a disabled module will be 5ignored, allowing another to take its place. This can be used to 6import a set of modules from another channel while keeping the rest of 7the system on a stable release. 8 9`disabledModules` is a top level attribute like `imports`, `options` and 10`config`. It contains a list of modules that will be disabled. This can 11either be: 12 - the full path to the module, 13 - or a string with the filename relative to the modules path (eg. \<nixpkgs/nixos/modules> for nixos), 14 - or an attribute set containing a specific `key` attribute. 15 16The latter allows some modules to be disabled, despite them being distributed 17via attributes instead of file paths. The `key` should be globally unique, so 18it is recommended to include a file path in it, or rely on a framework to do it 19for you. 20 21This example will replace the existing postgresql module with the 22version defined in the nixos-unstable channel while keeping the rest of 23the modules and packages from the original nixos channel. This only 24overrides the module definition, this won't use postgresql from 25nixos-unstable unless explicitly configured to do so. 26 27```nix 28{ 29 config, 30 lib, 31 pkgs, 32 ... 33}: 34 35{ 36 disabledModules = [ "services/databases/postgresql.nix" ]; 37 38 imports = [ 39 # Use postgresql service from nixos-unstable channel. 40 # sudo nix-channel --add https://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``` 47 48This example shows how to define a custom module as a replacement for an 49existing module. Importing this module will disable the original module 50without having to know its implementation details. 51 52```nix 53{ 54 config, 55 lib, 56 pkgs, 57 ... 58}: 59 60let 61 inherit (lib) mkIf mkOption types; 62 cfg = config.programs.man; 63 64in 65{ 66 disabledModules = [ "services/programs/man.nix" ]; 67 68 options = { 69 programs.man.enable = mkOption { 70 type = types.bool; 71 default = true; 72 description = "Whether to enable manual pages."; 73 }; 74 }; 75 76 config = mkIf cfg.enabled { 77 warnings = [ "disabled manpages for production deployments." ]; 78 }; 79} 80```