Skip to content

test(options-doc): test doc generation for module - #975

Merged
SuperSandro2000 merged 1 commit into
nix-community:mainfrom
sedlund:feat/docs-modules
Feb 9, 2026
Merged

test(options-doc): test doc generation for module#975
SuperSandro2000 merged 1 commit into
nix-community:mainfrom
sedlund:feat/docs-modules

Conversation

@sedlund

@sedlund sedlund commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Add a regression test to the CI suite that validates the evaluation of all NixOS module options.

Problem

A recent bug demonstrated that using config values inside an option's type definition (e.g., lib.attrNames config.users.users) causes documentation generation to fail with "missing attribute" or "infinite recursion" errors. These errors are often only discovered late in the development cycle or when building the project's documentation.

Solution

This PR introduces a new flake check, options-doc, which:

  1. Instantiates a minimal NixOS system using the WSL module.
  2. Enables documentation.nixos.includeAllModules = true.
  3. Attempts to build the options.json derivation.

By enabling includeAllModules, Nix is forced to deeply evaluate the type and description fields of every option in every module. If an option type contains a circular reference or relies on a config value that isn't available during doc-gen, this check will fail in CI.

Changes

  • Created checks/options-doc.nix: Logic to evaluate the system manual's options.
  • Updated flake.nix: Integrated the new check into the checks attribute set.

Verification

You can run this check locally with:

nix build .#checks.<system>.options-doc

Details Output:
 nix build .\#checks.x86_64-linux.options-doc
warning: Git tree '/home/sedlund/dev/sedlund/NixOS-WSL' is dirty
evaluation warning: 'system' has been renamed to/replaced by 'stdenv.hostPlatform.system'
error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:37:12:
           36|
           37|   strict = derivationStrict drvAttrs;
             |            ^
           38|while evaluating derivation 'options.json'
         whose name attribute is located at /nix/store/8rqf4w66r61rp58ffqnpjni2zlg4cyhs-source/pkgs/stdenv/generic/make-derivation.nix:536:13

       … while evaluating attribute 'options' of derivation 'options.json'
         at /nix/store/8rqf4w66r61rp58ffqnpjni2zlg4cyhs-source/nixos/lib/make-options-doc/default.nix:218:9:
          217|         passAsFile = [ "options" ];
          218|         options = builtins.unsafeDiscardStringContext (builtins.toJSON optionsNix);
             |         ^
          219|         # merge with an empty set if baseOptionsJSON is null to run markdown

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: attribute 'users' missing
       at /nix/store/wxrjb89gq31c306qybgb2zyhrcm6k3wi-source/modules/ssh-agent.nix:20:37:
           19|           inherit (lib.types) either enum listOf;
           20|           userNames = lib.attrNames config.users.users;
             |                                     ^
           21|         in

@sedlund

sedlund commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

Test successfully failed. 👍

Comment thread checks/options-doc.nix
@SuperSandro2000
SuperSandro2000 merged commit 5b50ea1 into nix-community:main Feb 9, 2026
70 of 74 checks passed
@nzbr nzbr changed the title feat(options-doc): test doc generation for module test(options-doc): test doc generation for module Mar 1, 2026
@nzbr nzbr added the tests Anything related to checks or tests label Mar 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Anything related to checks or tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants