summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2020-09-07 19:31:01 +0200
committerGitHub <noreply@github.com>2020-09-07 19:31:01 +0200
commitf73b762aacbc4740432d88be11960d066e0087eb (patch)
treef92cd6ff60ed84f01fac53462a37a91a20e4e1ec /lib
parent3c4335723cfbfb044a803eab0c89b836db8596e0 (diff)
parentf320dbae41cf875ea669b2a8b6083bf2a54f70ce (diff)
Merge pull request #97042 from Infinisil/freeform-option-docs
Show sub options of freeform types
Diffstat (limited to 'lib')
-rw-r--r--lib/tests/misc.nix26
-rw-r--r--lib/types.nix7
2 files changed, 32 insertions, 1 deletions
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index b066f577f323..03eff4ce48b7 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" "<name>" "bar" ] [ "foo" "bar" ] ];
+ };
+
}
diff --git a/lib/types.nix b/lib/types.nix
index 17e7a939fe3d..951fad291cca 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -427,7 +427,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;