diff options
author | Robert Hensing <robert@roberthensing.nl> | 2022-06-06 16:05:21 +0200 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2022-09-21 10:55:11 +0100 |
commit | 1ffa30b0559a05e810a3db663da5066953d4f05a (patch) | |
tree | 201ad912353ca43e6e7d57d36d4c7861481e105a /lib | |
parent | fce8b018f06431e7684b725a520416ff3862db9f (diff) |
lib/modules: Fix meta duplication in shorthand syntax
Diffstat (limited to 'lib')
-rw-r--r-- | lib/modules.nix | 3 | ||||
-rwxr-xr-x | lib/tests/modules.sh | 3 | ||||
-rw-r--r-- | lib/tests/modules/shorthand-meta.nix | 19 |
3 files changed, 24 insertions, 1 deletions
diff --git a/lib/modules.nix b/lib/modules.nix index d3a7fac82c4ab..28c8da9e923a3 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -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 diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 2ef7c48065952..57d3b5a76cec1 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -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 diff --git a/lib/tests/modules/shorthand-meta.nix b/lib/tests/modules/shorthand-meta.nix new file mode 100644 index 0000000000000..8c9619e18a2ab --- /dev/null +++ b/lib/tests/modules/shorthand-meta.nix @@ -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" ]; + } + ]; +} |