mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-14 15:36:47 +03:00
lib/modules: Fix meta duplication in shorthand syntax
This commit is contained in:
parent
fce8b018f0
commit
1ffa30b055
@ -440,13 +440,14 @@ rec {
|
||||
config = addFreeformType (addMeta (m.config or {}));
|
||||
}
|
||||
else
|
||||
# shorthand syntax
|
||||
lib.throwIfNot (isAttrs m) "module ${file} (${key}) does not look like a module."
|
||||
{ _file = toString m._file or file;
|
||||
key = toString m.key or key;
|
||||
disabledModules = m.disabledModules or [];
|
||||
imports = m.require or [] ++ m.imports or [];
|
||||
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
|
||||
|
@ -58,6 +58,9 @@ checkConfigError() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Shorthand meta attribute does not duplicate the config
|
||||
checkConfigOutput '^"one two"$' config.result ./shorthand-meta.nix
|
||||
|
||||
# Check boolean option.
|
||||
checkConfigOutput '^false$' config.enable ./declare-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 New Issue
Block a user