diff --git a/lib/jsonschema/default.nix b/lib/jsonschema/default.nix index f51d97218..73b511f8f 100644 --- a/lib/jsonschema/default.nix +++ b/lib/jsonschema/default.nix @@ -100,9 +100,12 @@ rec { defaultText ? null, ... }@attrs: + let + sanitizedAttrs = removeAttrs attrs (lib.optionals (defaultText != null) [ "default" ]); + in { "$exportedModuleInfo" = - attrs + sanitizedAttrs // { inherit path required; } diff --git a/lib/jsonschema/test_parseOption.nix b/lib/jsonschema/test_parseOption.nix index 3cdf32da0..50d204e12 100644 --- a/lib/jsonschema/test_parseOption.nix +++ b/lib/jsonschema/test_parseOption.nix @@ -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"; + }; + }; }