summary refs log tree commit diff
path: root/nixos/modules/misc
diff options
context:
space:
mode:
authorNaïm Favier <n@monade.li>2022-11-03 15:56:27 +0100
committerpennae <82953136+pennae@users.noreply.github.com>2022-12-08 17:52:52 +0100
commit6a117e2759b84b9508f1d69cb5be54ca331bff98 (patch)
tree5679f8c723a9c84da0fc40ba03bdfef6bb60e27c /nixos/modules/misc
parent0b661ce32af9baa07da56b3f48fcd3ef5611b66c (diff)
downloadnixpkgs-6a117e2759b84b9508f1d69cb5be54ca331bff98.tar
nixpkgs-6a117e2759b84b9508f1d69cb5be54ca331bff98.tar.gz
nixpkgs-6a117e2759b84b9508f1d69cb5be54ca331bff98.tar.bz2
nixpkgs-6a117e2759b84b9508f1d69cb5be54ca331bff98.tar.lz
nixpkgs-6a117e2759b84b9508f1d69cb5be54ca331bff98.tar.xz
nixpkgs-6a117e2759b84b9508f1d69cb5be54ca331bff98.tar.zst
nixpkgs-6a117e2759b84b9508f1d69cb5be54ca331bff98.zip
nixos/doc: render option values using `lib.generators.toPretty`
Render un`_type`d defaults and examples as `literalExpression`s using
`lib.generators.toPretty` so that consumers don't have to reinvent Nix
pretty-printing. `renderOptionValue` is kept internal for now intentionally.

Make `toPretty` print floats as valid Nix values (without a tilde).

Get rid of the now-obsolete `substSpecial` function.

Move towards disallowing evaluation of packages in the manual by
raising a warning on `pkgs.foo.{outPath,drvPath}`; later, this should
throw an error. Instead, module authors should use `literalExpression`
and `mkPackageOption`.
Diffstat (limited to 'nixos/modules/misc')
-rw-r--r--nixos/modules/misc/documentation.nix11
1 files changed, 8 insertions, 3 deletions
diff --git a/nixos/modules/misc/documentation.nix b/nixos/modules/misc/documentation.nix
index aa6e40f4370..64a8f7846b4 100644
--- a/nixos/modules/misc/documentation.nix
+++ b/nixos/modules/misc/documentation.nix
@@ -48,10 +48,15 @@ let
         };
         scrubDerivations = namePrefix: pkgSet: mapAttrs
           (name: value:
-            let wholeName = "${namePrefix}.${name}"; in
-            if isAttrs value then
+            let
+              wholeName = "${namePrefix}.${name}";
+              guard = lib.warn "Attempt to evaluate package ${wholeName} in option documentation; this is not supported and will eventually be an error. Use `mkPackageOption` or `literalExpression` instead.";
+            in if isAttrs value then
               scrubDerivations wholeName value
-              // (optionalAttrs (isDerivation value) { outPath = "\${${wholeName}}"; })
+              // optionalAttrs (isDerivation value) {
+                outPath = guard "\${${wholeName}}";
+                drvPath = guard drvPath;
+              }
             else value
           )
           pkgSet;