query
On this page

optionAttrSetToDocList

lib.options.optionAttrSetToDocList

Docs pulled from | This Revision | 18 minutes ago


Contribute
Enhance the ecosystem with your expertise! Contribute to fill the gaps in documentation. Your input can make a difference.

Noogle detected

Aliases

Implementation

The following is the current implementation of this function.

options:
    concatMap (
      opt:
      let
        name = showOption opt.loc;
        visible = opt.visible or true;
        docOption = {
          loc = opt.loc;
          inherit name;
          description = opt.description or null;
          declarations = filter (x: x != unknownModule) opt.declarations;
          internal = opt.internal or false;
          visible = if isBool visible then visible else visible == "shallow";
          readOnly = opt.readOnly or false;
          type = opt.type.description or "unspecified";
        }
        // optionalAttrs (opt ? example) {
          example = builtins.addErrorContext "while evaluating the example of option `${name}`" (
            renderOptionValue opt.example
          );
        }
        //
          optionalAttrs
            (
              opt ? defaultText
              || opt ? default
              # Render emptyValue-based defaults, but only for types without
              # submodules (e.g. types.submodule). Submodules may evaluate to
              # error without user defs, and their sub-options are documented
              # individually, so best to skip those here.
              || ((opt.type or { }).emptyValue or { }) ? value && (opt.type or { }).getSubModules or null == null
            )
            {
              default =
                builtins.addErrorContext
                  "while evaluating the ${
                    if opt ? defaultText then "defaultText" else "default value"
                  } of option `${name}`"
                  (renderOptionValue (opt.defaultText or opt.default or opt.type.emptyValue.value));
            }
        // optionalAttrs (opt ? relatedPackages && opt.relatedPackages != null) {
          inherit (opt) relatedPackages;
        };

        subOptions =
          let
            ss = opt.type.getSubOptions opt.loc;
          in
          if ss != { } then optionAttrSetToDocList' opt.loc ss else [ ];
        subOptionsVisible = if isBool visible then visible else visible == "transparent";
      in
      # To find infinite recursion in NixOS option docs:
      # builtins.trace opt.loc
      [ docOption ] ++ optionals subOptionsVisible subOptions
    ) (collect isOption options)