feat(jsonschema): remove 'default' if 'defaultText' is present

default is likely to contain an error thunk if defaultText is set
including it into $exportedModuleInfo makes it non-serializable
This commit is contained in:
Johannes Kirschbauer
2025-06-04 20:22:32 +02:00
parent f99ddab70f
commit cdaa35ca5f
2 changed files with 27 additions and 1 deletions

View File

@@ -100,9 +100,12 @@ rec {
defaultText ? null,
...
}@attrs:
let
sanitizedAttrs = removeAttrs attrs (lib.optionals (defaultText != null) [ "default" ]);
in
{
"$exportedModuleInfo" =
attrs
sanitizedAttrs
// {
inherit path required;
}

View File

@@ -568,4 +568,27 @@ in
type = "object";
};
};
# Default MUST not be evaluated if defaultText is present
test_default_lazyness = {
expr = (
parseOption (evalModuleOptions {
options.opt = lib.mkOption {
type = lib.types.bool;
default = throw "This option is lazy";
defaultText = "This option is lazy";
};
})
);
expected = {
additionalProperties = false;
properties = {
opt = {
type = "boolean";
};
};
required = [ ];
type = "object";
};
};
}