lib/modules: Fix meta duplication in shorthand syntax

Changed files
+24 -1
lib
+2 -1
lib/modules.nix
···
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
+3
lib/tests/modules.sh
···
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
···
+
{ 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" ];
+
}
+
];
+
}