diff options
Diffstat (limited to 'lib/modules.nix')
-rw-r--r-- | lib/modules.nix | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/lib/modules.nix b/lib/modules.nix index 573bf40e4b341..f1125aca0a352 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -37,6 +37,7 @@ let toList types warnIf + zipAttrsWith ; inherit (lib.options) isOption @@ -333,6 +334,10 @@ rec { in modulesPath: initialModules: args: filterModules modulesPath (collectStructuredModules unknownModule "" initialModules args); + /* Wrap a module with a default location for reporting errors. */ + setDefaultModuleLocation = file: m: + { _file = file; imports = [ m ]; }; + /* Massage a module into canonical form, that is, a set consisting of ‘options’, ‘config’ and ‘imports’ attributes. */ unifyModuleSyntax = file: key: m: @@ -442,10 +447,11 @@ rec { } */ byName = attr: f: modules: - foldl' (acc: module: - if !(builtins.isAttrs module.${attr}) then + zipAttrsWith (n: concatLists) + (map (module: let subtree = module.${attr}; in + if !(builtins.isAttrs subtree) then throw '' - You're trying to declare a value of type `${builtins.typeOf module.${attr}}' + You're trying to declare a value of type `${builtins.typeOf subtree}' rather than an attribute-set for the option `${builtins.concatStringsSep "." prefix}'! @@ -454,11 +460,8 @@ rec { this option by e.g. referring to `man 5 configuration.nix'! '' else - acc // (mapAttrs (n: v: - (acc.${n} or []) ++ f module v - ) module.${attr} - ) - ) {} modules; + mapAttrs (n: f module) subtree + ) modules); # an attrset 'name' => list of submodules that declare ‘name’. declsByName = byName "options" (module: option: [{ inherit (module) _file; options = option; }] @@ -535,11 +538,9 @@ rec { correspond to the definition of 'loc' in 'opt.file'. */ mergeOptionDecls = let - packSubmodule = file: m: - { _file = file; imports = [ m ]; }; coerceOption = file: opt: - if isFunction opt then packSubmodule file opt - else packSubmodule file { options = opt; }; + if isFunction opt then setDefaultModuleLocation file opt + else setDefaultModuleLocation file { options = opt; }; in loc: opts: foldl' (res: opt: let t = res.type; @@ -569,7 +570,7 @@ rec { getSubModules = opt.options.type.getSubModules or null; submodules = - if getSubModules != null then map (packSubmodule opt._file) getSubModules ++ res.options + if getSubModules != null then map (setDefaultModuleLocation opt._file) getSubModules ++ res.options else if opt.options ? options then map (coerceOption opt._file) options' ++ res.options else res.options; in opt.options // res // |