From 7a7bcf68c6bb6869e4eaa88dd11289b690beef35 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 4 Jun 2025 20:22:32 +0200 Subject: [PATCH] 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 --- lib/jsonschema/default.nix | 5 ++++- lib/jsonschema/test_parseOption.nix | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) 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"; + }; + }; }