From ea5ba6e13d8b359059245668b69fe72e6d2a6211 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 3 Sep 2020 21:16:29 +0200 Subject: [PATCH 1/2] lib/types: Show sub options of freeform types Previously if you set the freeform type to e.g. attrsOf (submodule ..), those submodule options wouldn't be shown in the manual. --- lib/types.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/types.nix b/lib/types.nix index 1845b6ae339..cc125c20311 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -522,7 +522,12 @@ rec { # would be used, and use of `<` and `>` would break the XML document. # It shouldn't cause an issue since this is cosmetic for the manual. args.name = "‹name›"; - }).options; + }).options // optionalAttrs (freeformType != null) { + # Expose the sub options of the freeform type. Note that the option + # discovery doesn't care about the attribute name used here, so this + # is just to avoid conflicts with potential options from the submodule + _freeformOptions = freeformType.getSubOptions prefix; + }; getSubModules = modules; substSubModules = m: submoduleWith (attrs // { modules = m; From f320dbae41cf875ea669b2a8b6083bf2a54f70ce Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 4 Sep 2020 15:50:13 +0200 Subject: [PATCH 2/2] lib/tests: Add test for freeform option docs --- lib/tests/misc.nix | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index b066f577f32..03eff4ce48b 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -542,4 +542,30 @@ runTests { name = ""; expected = "unknown"; }; + + testFreeformOptions = { + expr = + let + submodule = { lib, ... }: { + freeformType = lib.types.attrsOf (lib.types.submodule { + options.bar = lib.mkOption {}; + }); + options.bar = lib.mkOption {}; + }; + + module = { lib, ... }: { + options.foo = lib.mkOption { + type = lib.types.submodule submodule; + }; + }; + + options = (evalModules { + modules = [ module ]; + }).options; + + locs = filter (o: ! o.internal) (optionAttrSetToDocList options); + in map (o: o.loc) locs; + expected = [ [ "foo" ] [ "foo" "" "bar" ] [ "foo" "bar" ] ]; + }; + }