Skip to content

Show sub options of freeform types#97042

Merged
infinisil merged 2 commits intoNixOS:masterfrom
infinisil:freeform-option-docs
Sep 7, 2020
Merged

Show sub options of freeform types#97042
infinisil merged 2 commits intoNixOS:masterfrom
infinisil:freeform-option-docs

Conversation

@infinisil
Copy link
Member

@infinisil infinisil commented Sep 3, 2020

Motivation for this change

Previously if you set the freeform type (as introduced in #82743) to e.g. attrsOf (submodule ..), those submodule options wouldn't be shown in the manual.

Originally this problem was brought to my attention by @alexarice

With an option declaration like

{ lib, ... }: {
  options.foofoofoo = lib.mkOption {
    type = lib.types.submodule {
      freeformType = lib.types.attrsOf (lib.types.submodule {
        options.bar = lib.mkOption {
          description = "Freeform bar";
        };
      });
      options.qux.bar = lib.mkOption {
        description = "Qux bar";
      };
      options.bar = lib.mkOption {
        description = "Submodule bar";
      };
    };
  };
}

The manual now correctly shows

2020-09-03_21-17

Ping @roberth

Things done
  • Checked that the manual still builds
  • Checked that even more complex cases like freeformType = attrsOf (attrsOf (submodule { freeformType = attrsOf ... work
  • Added a test for checking that submodule options are present

Previously if you set the freeform type to e.g. attrsOf (submodule ..),
those submodule options wouldn't be shown in the manual.
@infinisil infinisil added the 6.topic: module system About "NixOS" module system internals label Sep 3, 2020
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion and it would be nice to have a simple test case for this.

@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Sep 3, 2020
@alexarice
Copy link
Contributor

Just checked out the change on my code and seems to work well. Thanks @infinisil

Only nitpick is the following:
screenshot46

Is there a way to stop this top level package appearing in the documentation?

@infinisil
Copy link
Member Author

@roberth Added a test for that

@alexarice Not possible as of now, but I'll keep this use case in mind if I happen to touch the relevant code for it :)

@infinisil infinisil merged commit f73b762 into NixOS:master Sep 7, 2020
@infinisil infinisil deleted the freeform-option-docs branch September 7, 2020 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: module system About "NixOS" module system internals 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants