@@ -20,7 +20,8 @@ rec {
2020 , prefix ? []
2121 , # This should only be used for special arguments that need to be evaluated
2222 # when resolving module structure (like in imports). For everything else,
23− # there's _module.args.
23+ # there's _module.args. If specialArgs.modulesPath is defined it will be
24+ # used as the base path for disabledModules.
2425 specialArgs ? {}
2526 , # This would be remove in the future, Prefer _module.args option instead.
2627 args ? {}
@@ -58,10 +59,7 @@ rec {
5859
5960 closed = closeModules (modules ++ [ internalModule ]) ({ inherit config options; lib = import ./.; } // specialArgs);
6061
61− # Note: the list of modules is reversed to maintain backward
62− # compatibility with the old module system. Not sure if this is
63− # the most sensible policy.
64− options = mergeModules prefix (reverseList closed);
62+ options = mergeModules prefix (reverseList (filterModules (specialArgs.modulesPath or "") closed));
6563
6664 # Traverse options and extract the option values into the final
6765 # config set. At the same time, check whether all option
@@ -87,6 +85,16 @@ rec {
8785 result = { inherit options config; };
8886 in result;
8987
88+
89+ # Filter disabled modules. Modules can be disabled allowing
90+ # their implementation to be replaced.
91+ filterModules = modulesPath: modules:
92+ let
93+ moduleKey = m: if isString m then toString modulesPath + "/" + m else toString m;
94+ disabledKeys = map moduleKey (concatMap (m: m.disabledModules) modules);
95+ in
96+ filter (m: !(elem m.key disabledKeys)) modules;
97+
9098 /* Close a set of modules under the ‘imports’ relation. */
9199 closeModules = modules: args:
92100 let
@@ -111,12 +119,13 @@ rec {
111119 else {};
112120 in
113121 if m ? config || m ? options then
114− let badAttrs = removeAttrs m ["imports" "options" "config" "key" "_file" "meta"]; in
122+ let badAttrs = removeAttrs m ["_file" "key" "disabledModules" "imports" "options" "config" "meta"]; in
115123 if badAttrs != {} then
116124 throw "Module `${key}' has an unsupported attribute `${head (attrNames badAttrs)}'. This is caused by assignments to the top-level attributes `config' or `options'."
117125 else
118126 { file = m._file or file;
119127 key = toString m.key or key;
128+ disabledModules = m.disabledModules or [];
120129 imports = m.imports or [];
121130 options = m.options or {};
122131 config = mkMerge [ (m.config or {}) metaSet ];
@@ -124,9 +133,10 @@ rec {
124133 else
125134 { file = m._file or file;
126135 key = toString m.key or key;
136+ disabledModules = m.disabledModules or [];
127137 imports = m.require or [] ++ m.imports or [];
128138 options = {};
129− config = mkMerge [ (removeAttrs m ["key" "_file" "require" "imports"]) metaSet ];
139+ config = mkMerge [ (removeAttrs m ["_file" "key" "disabledModules" "require" "imports"]) metaSet ];
130140 };
131141
132142 applyIfFunction = key: f: args@{ config, options, lib, ... }: if isFunction f then