lib/modules: Fix meta duplication in shorthand syntax
This commit is contained in:
parent
fce8b018f0
commit
1ffa30b055
3 changed files with 24 additions and 1 deletions
|
@ -440,13 +440,14 @@ rec {
|
||||||
config = addFreeformType (addMeta (m.config or {}));
|
config = addFreeformType (addMeta (m.config or {}));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
# shorthand syntax
|
||||||
lib.throwIfNot (isAttrs m) "module ${file} (${key}) does not look like a module."
|
lib.throwIfNot (isAttrs m) "module ${file} (${key}) does not look like a module."
|
||||||
{ _file = toString m._file or file;
|
{ _file = toString 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 [];
|
||||||
options = {};
|
options = {};
|
||||||
config = addFreeformType (addMeta (removeAttrs m ["_file" "key" "disabledModules" "require" "imports" "freeformType"]));
|
config = addFreeformType (removeAttrs m ["_file" "key" "disabledModules" "require" "imports" "freeformType"]);
|
||||||
};
|
};
|
||||||
|
|
||||||
applyModuleArgsIfFunction = key: f: args@{ config, options, lib, ... }: if isFunction f then
|
applyModuleArgsIfFunction = key: f: args@{ config, options, lib, ... }: if isFunction f then
|
||||||
|
|
|
@ -58,6 +58,9 @@ checkConfigError() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Shorthand meta attribute does not duplicate the config
|
||||||
|
checkConfigOutput '^"one two"$' config.result ./shorthand-meta.nix
|
||||||
|
|
||||||
# Check boolean option.
|
# Check boolean option.
|
||||||
checkConfigOutput '^false$' config.enable ./declare-enable.nix
|
checkConfigOutput '^false$' config.enable ./declare-enable.nix
|
||||||
checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./define-enable.nix
|
checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./define-enable.nix
|
||||||
|
|
19
lib/tests/modules/shorthand-meta.nix
Normal file
19
lib/tests/modules/shorthand-meta.nix
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{ lib, ... }:
|
||||||
|
let
|
||||||
|
inherit (lib) types mkOption;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
({ config, ... }: {
|
||||||
|
options = {
|
||||||
|
meta.foo = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
};
|
||||||
|
result = mkOption { default = lib.concatStringsSep " " config.meta.foo; };
|
||||||
|
};
|
||||||
|
})
|
||||||
|
{
|
||||||
|
meta.foo = [ "one" "two" ];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
Loading…
Reference in a new issue