feat: support submodule longhand

This commit is contained in:
Jake Hamilton 2024-06-14 17:26:58 -07:00
parent 3713635d76
commit aa1c58f6ee
Signed by untrusted user: jakehamilton
GPG key ID: 9762169A1B35EA68
2 changed files with 43 additions and 3 deletions

View file

@ -454,5 +454,44 @@ in {
}; };
in in
evaluated.config.aux.x.message == expected; evaluated.config.aux.x.message == expected;
"submodules without shorthand" = let
expected = "Hello, World!";
evaluated = lib.modules.run {
modules = [
{
options = {
aux = lib.options.create {
type = lib.types.submodules.of {
shorthand = false;
modules = [
{
options.message = lib.options.create {
type = lib.types.string;
};
}
];
};
};
};
config = {
aux = {
options = {
message2 = lib.options.create {
type = lib.types.string;
};
};
config = {
message = expected;
message2 = expected;
};
};
};
}
];
};
in
evaluated.config.aux.message == evaluated.config.aux.message2;
}; };
} }

View file

@ -761,10 +761,11 @@ lib: {
modules, modules,
args ? {}, args ? {},
description ? null, description ? null,
shorthand ? true,
}: let }: let
getModules = builtins.map ( getModules = builtins.map (
definition: definition:
if builtins.isAttrs definition if shorthand && builtins.isAttrs definition
then { then {
__file__ = definition.__file__; __file__ = definition.__file__;
config = definition.value; config = definition.value;
@ -816,7 +817,7 @@ lib: {
getSubModules = modules; getSubModules = modules;
withSubModules = modules: withSubModules = modules:
lib.types.submodules.of { lib.types.submodules.of {
inherit args description modules; inherit args description modules shorthand;
}; };
children = lib.attrs.when (freeform != null) { children = lib.attrs.when (freeform != null) {
inherit freeform; inherit freeform;
@ -826,7 +827,7 @@ lib: {
// { // {
type = lib.types.submodules.of; type = lib.types.submodules.of;
payload = { payload = {
inherit modules args description; inherit modules args description shorthand;
}; };
merge = x: y: { merge = x: y: {
modules = x.modules ++ y.modules; modules = x.modules ++ y.modules;