lib.options: reflect emptyValue-based option defaults in documentation
Signed-off-by: cinereal <cinereal@riseup.net>
This commit is contained in:
+10
-5
@@ -589,11 +589,16 @@ rec {
|
||||
renderOptionValue opt.example
|
||||
);
|
||||
}
|
||||
// optionalAttrs (opt ? defaultText || opt ? default) {
|
||||
default = builtins.addErrorContext "while evaluating the ${
|
||||
if opt ? defaultText then "defaultText" else "default value"
|
||||
} of option `${name}`" (renderOptionValue (opt.defaultText or opt.default));
|
||||
}
|
||||
//
|
||||
optionalAttrs (opt ? defaultText || opt ? default || ((opt.type or { }).emptyValue or { }) ? value)
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -3393,6 +3393,44 @@ runTests {
|
||||
];
|
||||
};
|
||||
|
||||
testEmptyValueOption = {
|
||||
expr =
|
||||
let
|
||||
module =
|
||||
{ lib, ... }:
|
||||
{
|
||||
options = {
|
||||
"empty-value" = lib.mkOption {
|
||||
type = lib.mkOptionType {
|
||||
name = "propagate-empty-value-to-default";
|
||||
emptyValue.value = 2;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
eval = evalModules {
|
||||
modules = [ module ];
|
||||
};
|
||||
in
|
||||
filter (o: o.name == "empty-value") (optionAttrSetToDocList eval.options);
|
||||
expected = [
|
||||
{
|
||||
declarations = [ ];
|
||||
default = {
|
||||
_type = "literalExpression";
|
||||
text = "2";
|
||||
};
|
||||
description = null;
|
||||
internal = false;
|
||||
loc = [ "empty-value" ];
|
||||
name = "empty-value";
|
||||
readOnly = false;
|
||||
type = "propagate-empty-value-to-default";
|
||||
visible = true;
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
testDocOptionVisiblity = {
|
||||
expr =
|
||||
let
|
||||
|
||||
Reference in New Issue
Block a user