lib/modules: Add syntactic sugar for config._module.freeformType
This introduces `freeformType` as a top-level module attribute, allowing definitions like { freeformType = ...; options = ...; config = ...; }
This commit is contained in:
parent
e0ded8f4ba
commit
42cf8130d7
@ -200,12 +200,16 @@ rec {
|
|||||||
/* Massage a module into canonical form, that is, a set consisting
|
/* Massage a module into canonical form, that is, a set consisting
|
||||||
of ‘options’, ‘config’ and ‘imports’ attributes. */
|
of ‘options’, ‘config’ and ‘imports’ attributes. */
|
||||||
unifyModuleSyntax = file: key: m:
|
unifyModuleSyntax = file: key: m:
|
||||||
let addMeta = config: if m ? meta
|
let
|
||||||
then mkMerge [ config { meta = m.meta; } ]
|
addMeta = config: if m ? meta
|
||||||
else config;
|
then mkMerge [ config { meta = m.meta; } ]
|
||||||
|
else config;
|
||||||
|
addFreeformType = config: if m ? freeformType
|
||||||
|
then mkMerge [ config { _module.freeformType = m.freeformType; } ]
|
||||||
|
else config;
|
||||||
in
|
in
|
||||||
if m ? config || m ? options then
|
if m ? config || m ? options then
|
||||||
let badAttrs = removeAttrs m ["_file" "key" "disabledModules" "imports" "options" "config" "meta"]; in
|
let badAttrs = removeAttrs m ["_file" "key" "disabledModules" "imports" "options" "config" "meta" "freeformType"]; in
|
||||||
if badAttrs != {} then
|
if badAttrs != {} then
|
||||||
throw "Module `${key}' has an unsupported attribute `${head (attrNames badAttrs)}'. This is caused by introducing a top-level `config' or `options' attribute. Add configuration attributes immediately on the top level instead, or move all of them (namely: ${toString (attrNames badAttrs)}) into the explicit `config' attribute."
|
throw "Module `${key}' has an unsupported attribute `${head (attrNames badAttrs)}'. This is caused by introducing a top-level `config' or `options' attribute. Add configuration attributes immediately on the top level instead, or move all of them (namely: ${toString (attrNames badAttrs)}) into the explicit `config' attribute."
|
||||||
else
|
else
|
||||||
@ -214,7 +218,7 @@ rec {
|
|||||||
disabledModules = m.disabledModules or [];
|
disabledModules = m.disabledModules or [];
|
||||||
imports = m.imports or [];
|
imports = m.imports or [];
|
||||||
options = m.options or {};
|
options = m.options or {};
|
||||||
config = addMeta (m.config or {});
|
config = addFreeformType (addMeta (m.config or {}));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ _file = m._file or file;
|
{ _file = m._file or file;
|
||||||
@ -222,7 +226,7 @@ rec {
|
|||||||
disabledModules = m.disabledModules or [];
|
disabledModules = m.disabledModules or [];
|
||||||
imports = m.require or [] ++ m.imports or [];
|
imports = m.require or [] ++ m.imports or [];
|
||||||
options = {};
|
options = {};
|
||||||
config = addMeta (removeAttrs m ["_file" "key" "disabledModules" "require" "imports"]);
|
config = addFreeformType (addMeta (removeAttrs m ["_file" "key" "disabledModules" "require" "imports" "freeformType"]));
|
||||||
};
|
};
|
||||||
|
|
||||||
applyIfFunction = key: f: args@{ config, options, lib, ... }: if isFunction f then
|
applyIfFunction = key: f: args@{ config, options, lib, ... }: if isFunction f then
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
{ lib, ... }: {
|
{ lib, ... }: {
|
||||||
config._module.freeformType = with lib.types; attrsOf (either str (attrsOf str));
|
freeformType = with lib.types; attrsOf (either str (attrsOf str));
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
{ lib, ... }: {
|
{ lib, ... }: {
|
||||||
config._module.freeformType = with lib.types; lazyAttrsOf (either str (lazyAttrsOf str));
|
freeformType = with lib.types; lazyAttrsOf (either str (lazyAttrsOf str));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user