lib/values: fix submodule and submoduleWith with external modules

This commit is contained in:
Johannes Kirschbauer
2024-12-06 21:01:27 +01:00
parent 6096e619ca
commit cd288b421c
2 changed files with 43 additions and 10 deletions

View File

@@ -36,7 +36,10 @@ let
options = filteredSubOptions;
modules = (
[
{ inherit options; }
{
inherit options;
_file = "<artifical submodule>";
}
]
++ map (config: { inherit config; }) defs.${attrName}
);
@@ -63,13 +66,7 @@ let
submodulePrios =
let
options = filteredSubOptions;
modules = (
[
{ inherit options; }
]
++ opt.definitions
);
modules = (opt.definitions ++ opt.type.getSubModules);
submoduleEval = lib.evalModules {
inherit modules;
};
@@ -80,8 +77,8 @@ let
if opt ? type && opt.type.name == "submodule" then
(prio) // submodulePrios
else if opt ? type && opt.type.name == "attrsOf" then
prio // (
prioPerValue {
prio
// (prioPerValue {
type = opt.type;
defs = zipDefs opt.definitions;
} (lib.modules.mergeAttrDefinitionsWithPrio opt))

View File

@@ -130,6 +130,42 @@ in
};
};
test_submoduleWith =
let
evaluated = (
eval [
{
options.foo = lib.mkOption {
type = lib.types.submoduleWith {
modules = [
{
options.bar = lib.mkOption {
type = lib.types.bool;
};
}
];
};
};
}
{
foo.bar = false;
}
]
);
in
{
inherit evaluated;
expr = slib.getPrios {
options = evaluated.options;
};
expected = {
foo = {
__prio = 100;
bar.__prio = 100; # Set via other module
};
};
};
# TODO(@hsjobeki): Cover this edge case
# test_freeform =
# let