mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-09 19:13:26 +03:00
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:
parent
859328f27e
commit
e09cf9f066
2 changed files with 65 additions and 2 deletions
|
@ -2830,6 +2830,42 @@ runTests {
|
|||
expected = "unknown";
|
||||
};
|
||||
|
||||
# https://github.com/NixOS/nixpkgs/issues/396849
|
||||
"test: submodule definitions aren't unchecked when evaluating submodule documentation" = {
|
||||
expr =
|
||||
let
|
||||
module =
|
||||
{ lib, ... }:
|
||||
{
|
||||
options.foo = lib.mkOption { type = lib.types.submodule submodule; };
|
||||
};
|
||||
|
||||
submodule = {
|
||||
options.bar = lib.mkOption { type = lib.types.int; };
|
||||
config.submoduleWrong = throw "yikes";
|
||||
};
|
||||
|
||||
options = (evalModules { modules = [ module ]; }).options;
|
||||
|
||||
renderableOpts = filter (o: !o.internal) (optionAttrSetToDocList options);
|
||||
# Evaluate the whole docs
|
||||
in
|
||||
builtins.deepSeq renderableOpts
|
||||
# Return the locations
|
||||
(map (o: o.loc) renderableOpts);
|
||||
expected = [
|
||||
[
|
||||
"_module"
|
||||
"args"
|
||||
]
|
||||
[ "foo" ]
|
||||
[
|
||||
"foo"
|
||||
"bar"
|
||||
]
|
||||
];
|
||||
};
|
||||
|
||||
testFreeformOptions = {
|
||||
expr =
|
||||
let
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue