lib/modules: file -> _file for a more idempotent unifyModuleSyntax

This will be useful for doing more complicated module evaluations
This commit is contained in:
Silvan Mosberger 2019-12-05 00:00:47 +01:00
parent bc471c14db
commit aa613427b7
No known key found for this signature in database
GPG Key ID: E8F1E9EAD284E17D
1 changed files with 10 additions and 10 deletions

View File

@ -110,7 +110,7 @@ rec {
in in
builtins.genericClosure { builtins.genericClosure {
startSet = toClosureList unknownModule "" modules; startSet = toClosureList unknownModule "" modules;
operator = m: toClosureList m.file m.key m.imports; operator = m: toClosureList m._file m.key m.imports;
}; };
/* Massage a module into canonical form, that is, a set consisting /* Massage a module into canonical form, that is, a set consisting
@ -125,7 +125,7 @@ rec {
if badAttrs != {} then if badAttrs != {} then
throw "Module `${key}' has an unsupported attribute `${head (attrNames badAttrs)}'. This is caused by assignments to the top-level attributes `config' or `options'." throw "Module `${key}' has an unsupported attribute `${head (attrNames badAttrs)}'. This is caused by assignments to the top-level attributes `config' or `options'."
else else
{ file = m._file or file; { _file = m._file or file;
key = toString m.key or key; key = toString m.key or key;
disabledModules = m.disabledModules or []; disabledModules = m.disabledModules or [];
imports = m.imports or []; imports = m.imports or [];
@ -133,7 +133,7 @@ rec {
config = mkMerge [ (m.config or {}) metaSet ]; config = mkMerge [ (m.config or {}) metaSet ];
} }
else else
{ file = m._file or file; { _file = m._file or file;
key = toString m.key or key; key = toString m.key or key;
disabledModules = m.disabledModules or []; disabledModules = m.disabledModules or [];
imports = m.require or [] ++ m.imports or []; imports = m.require or [] ++ m.imports or [];
@ -189,7 +189,7 @@ rec {
in the value attribute of each option. */ in the value attribute of each option. */
mergeModules = prefix: modules: mergeModules = prefix: modules:
mergeModules' prefix modules mergeModules' prefix modules
(concatMap (m: map (config: { inherit (m) file; inherit config; }) (pushDownProperties m.config)) modules); (concatMap (m: map (config: { file = m._file; inherit config; }) (pushDownProperties m.config)) modules);
mergeModules' = prefix: options: configs: mergeModules' = prefix: options: configs:
let let
@ -223,7 +223,7 @@ rec {
) {} modules; ) {} modules;
# an attrset 'name' => list of submodules that declare name. # an attrset 'name' => list of submodules that declare name.
declsByName = byName "options" (module: option: declsByName = byName "options" (module: option:
[{ inherit (module) file; options = option; }] [{ inherit (module) _file; options = option; }]
) options; ) options;
# an attrset 'name' => list of submodules that define name. # an attrset 'name' => list of submodules that define name.
defnsByName = byName "config" (module: value: defnsByName = byName "config" (module: value:
@ -250,7 +250,7 @@ rec {
firstOption = findFirst (m: isOption m.options) "" decls; firstOption = findFirst (m: isOption m.options) "" decls;
firstNonOption = findFirst (m: !isOption m.options) "" decls; firstNonOption = findFirst (m: !isOption m.options) "" decls;
in in
throw "The option `${showOption loc}' in `${firstOption.file}' is a prefix of options in `${firstNonOption.file}'." throw "The option `${showOption loc}' in `${firstOption._file}' is a prefix of options in `${firstNonOption._file}'."
else else
mergeModules' loc decls defns mergeModules' loc decls defns
)) ))
@ -284,7 +284,7 @@ rec {
bothHave "apply" || bothHave "apply" ||
(bothHave "type" && (! typesMergeable)) (bothHave "type" && (! typesMergeable))
then then
throw "The option `${showOption loc}' in `${opt.file}' is already declared in ${showFiles res.declarations}." throw "The option `${showOption loc}' in `${opt._file}' is already declared in ${showFiles res.declarations}."
else else
let let
/* Add the modules of the current option to the list of modules /* Add the modules of the current option to the list of modules
@ -298,11 +298,11 @@ rec {
else packSubmodule file { options = opt; }; else packSubmodule file { options = opt; };
getSubModules = opt.options.type.getSubModules or null; getSubModules = opt.options.type.getSubModules or null;
submodules = submodules =
if getSubModules != null then map (packSubmodule opt.file) getSubModules ++ res.options if getSubModules != null then map (packSubmodule opt._file) getSubModules ++ res.options
else if opt.options ? options then map (coerceOption opt.file) options' ++ res.options else if opt.options ? options then map (coerceOption opt._file) options' ++ res.options
else res.options; else res.options;
in opt.options // res // in opt.options // res //
{ declarations = res.declarations ++ [opt.file]; { declarations = res.declarations ++ [opt._file];
options = submodules; options = submodules;
} // typeSet } // typeSet
) { inherit loc; declarations = []; options = []; } opts; ) { inherit loc; declarations = []; options = []; } opts;