lib.types.submodule: Disable check during docs generation

Put simply docs generation is a weird eval, and we should avoid
generating any unnecessary errors.
This commit is contained in:
Robert Hensing 2025-04-07 21:50:57 +02:00
parent 859328f27e
commit e09cf9f066
2 changed files with 65 additions and 2 deletions

View file

@ -290,6 +290,15 @@ let
unparenthesize: t:
if unparenthesize (t.descriptionClass or null) then t.description else "(${t.description})";
noCheckForDocsModule = {
# When generating documentation, our goal isn't to check anything.
# Quite the opposite in fact. Generating docs is somewhat of a
# challenge, evaluating modules in a *lacking* context. Anything
# that makes the docs avoid an error is a win.
config._module.check = lib.mkForce false;
_file = "<built-in module that disables checks for the purpose of documentation generation>";
};
# When adding new types don't forget to document them in
# nixos/doc/manual/development/option-types.section.md!
types = rec {
@ -1209,7 +1218,14 @@ let
in
mkOptionType {
inherit name;
description = if description != null then description else freeformType.description or name;
description =
if description != null then
description
else
let
docsEval = base.extendModules { modules = [ noCheckForDocsModule ]; };
in
docsEval._module.freeformType.description or name;
check = x: isAttrs x || isFunction x || path.check x;
merge =
loc: defs:
@ -1222,7 +1238,18 @@ let
};
getSubOptions =
prefix:
(base.extendModules { inherit prefix; }).options
let
docsEval = (
base.extendModules {
inherit prefix;
modules = [ noCheckForDocsModule ];
}
);
# Intentionally shadow the freeformType from the possibly *checked*
# configuration. See `noCheckForDocsModule` comment.
inherit (docsEval._module) freeformType;
in
docsEval.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