lib/options: fix rendering of options with only a defaultText

Some options have their default value set in the `config` instead of
`default`, for example to push `mkDefault`s down an attribute set.
In those cases, it's useful to provide a `defaultText` for informational
purposes.
This commit is contained in:
Naïm Favier 2023-05-06 16:50:08 +02:00
parent 276f75e5ff
commit 7cd5b9a6e8
No known key found for this signature in database
GPG key ID: 95AFCE8211908325

View file

@ -261,7 +261,7 @@ rec {
concatMap (opt:
let
name = showOption opt.loc;
docOption = rec {
docOption = {
loc = opt.loc;
inherit name;
description = opt.description or null;
@ -280,9 +280,9 @@ rec {
renderOptionValue opt.example
);
}
// optionalAttrs (opt ? default) {
// optionalAttrs (opt ? defaultText || opt ? default) {
default =
builtins.addErrorContext "while evaluating the default value of option `${name}`" (
builtins.addErrorContext "while evaluating the ${if opt?defaultText then "defaultText" else "default value"} of option `${name}`" (
renderOptionValue (opt.defaultText or opt.default)
);
}