From 7cd5b9a6e8c3e4e423d7d10533cc2f1e98a4eca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Sat, 6 May 2023 16:50:08 +0200 Subject: [PATCH] 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. --- lib/options.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/options.nix b/lib/options.nix index 4780a56fc1c3..d71d9421b7b1 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -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) ); }