lib/modules: Fix meta duplication in shorthand syntax

This commit is contained in:
Robert Hensing 2022-06-06 16:05:21 +02:00
parent fce8b018f0
commit 1ffa30b055
3 changed files with 24 additions and 1 deletions

View file

@ -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

View file

@ -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

View 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" ];
}
];
}