From cd048c21141aae2f63800a3907437e17ffc9777e Mon Sep 17 00:00:00 2001 From: DavHau Date: Wed, 9 Aug 2023 18:19:36 +0200 Subject: [PATCH] lan-config: handle nested options --- lib/jsonschema/default.nix | 8 +++++++- lib/jsonschema/test_parseOptions.nix | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/jsonschema/default.nix b/lib/jsonschema/default.nix index 2e6ab09b3..7a263f05d 100644 --- a/lib/jsonschema/default.nix +++ b/lib/jsonschema/default.nix @@ -56,7 +56,13 @@ rec { inherit (option) description; }; in - if option._type != "option" + + # handle nested options (not a submodule) + if ! option ? _type + then parseOptions option + + # throw if not an option + else if option._type != "option" then throw "parseOption: not an option" # parse nullOr diff --git a/lib/jsonschema/test_parseOptions.nix b/lib/jsonschema/test_parseOptions.nix index c635286de..c4564a7ea 100644 --- a/lib/jsonschema/test_parseOptions.nix +++ b/lib/jsonschema/test_parseOptions.nix @@ -17,4 +17,30 @@ in expr = slib.parseOptions evaledOptions; expected = builtins.fromJSON (builtins.readFile ./example-schema.json); }; + + testParseNestedOptions = + let + evaled = lib.evalModules { + modules = [{ + options.foo.bar = lib.mkOption { + type = lib.types.bool; + }; + }]; + }; + in + { + expr = slib.parseOptions evaled.options; + expected = { + properties = { + foo = { + properties = { + bar = { type = "boolean"; }; + }; + required = [ "bar" ]; + type = "object"; + }; + }; + type = "object"; + }; + }; }