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: jakehamilton
GPG key ID: 9762169A1B35EA68
2 changed files with 43 additions and 3 deletions

View file

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