summary refs log tree commit diff
path: root/nixos/modules/services/misc/nixos-manual.nix
diff options
context:
space:
mode:
authorVladimír Čunát <vcunat@gmail.com>2016-02-27 10:48:12 +0100
committerVladimír Čunát <vcunat@gmail.com>2016-02-27 10:48:12 +0100
commit3cf9cd8bc30c5e271822adaeb5069b19879acc8c (patch)
treece9fe94c3ed47c78ac741fb35f572aa6bcece2a8 /nixos/modules/services/misc/nixos-manual.nix
parenta8b44c74d351a60c7b6c7e30d8b62b85aaa00f94 (diff)
parent4fede53c0996938979d2966a69f108782a8c1c12 (diff)
downloadnixlib-3cf9cd8bc30c5e271822adaeb5069b19879acc8c.tar
nixlib-3cf9cd8bc30c5e271822adaeb5069b19879acc8c.tar.gz
nixlib-3cf9cd8bc30c5e271822adaeb5069b19879acc8c.tar.bz2
nixlib-3cf9cd8bc30c5e271822adaeb5069b19879acc8c.tar.lz
nixlib-3cf9cd8bc30c5e271822adaeb5069b19879acc8c.tar.xz
nixlib-3cf9cd8bc30c5e271822adaeb5069b19879acc8c.tar.zst
nixlib-3cf9cd8bc30c5e271822adaeb5069b19879acc8c.zip
Merge #12796: nixos docs: show references to packages
(version 2) A better implementation of #10039, after #12357.
This time I did more thorough checking.

See commit messages for details.
Diffstat (limited to 'nixos/modules/services/misc/nixos-manual.nix')
-rw-r--r--nixos/modules/services/misc/nixos-manual.nix31
1 files changed, 23 insertions, 8 deletions
diff --git a/nixos/modules/services/misc/nixos-manual.nix b/nixos/modules/services/misc/nixos-manual.nix
index 79943a21224b..37ea339300d4 100644
--- a/nixos/modules/services/misc/nixos-manual.nix
+++ b/nixos/modules/services/misc/nixos-manual.nix
@@ -17,16 +17,32 @@ let
       nixpkgs.system = config.nixpkgs.system;
     };
 
-  eval = evalModules {
-    modules = [ versionModule ] ++ baseModules;
-    args = (config._module.args) // { modules = [ ]; };
-  };
-
+  /* For the purpose of generating docs, evaluate options with each derivation
+    in `pkgs` (recursively) replaced by a fake with path "\${pkgs.attribute.path}".
+    It isn't perfect, but it seems to cover a vast majority of use cases.
+    Caveat: even if the package is reached by a different means,
+    the path above will be shown and not e.g. `${config.services.foo.package}`. */
   manual = import ../../../doc/manual {
     inherit pkgs;
     version = config.system.nixosVersion;
     revision = config.system.nixosRevision;
-    options = eval.options;
+    options =
+      let
+        scrubbedEval = evalModules {
+          modules = [ versionModule ] ++ baseModules;
+          args = (config._module.args) // { modules = [ ]; };
+          specialArgs = { pkgs = scrubDerivations "pkgs" pkgs; };
+        };
+        scrubDerivations = namePrefix: pkgSet: mapAttrs
+          (name: value:
+            let wholeName = "${namePrefix}.${name}"; in
+            if isAttrs value then
+              scrubDerivations wholeName value
+              // (optionalAttrs (isDerivation value) { outPath = "\${${wholeName}}"; })
+            else value
+          )
+          pkgSet;
+      in scrubbedEval.options;
   };
 
   entry = "${manual.manual}/share/doc/nixos/index.html";
@@ -81,6 +97,7 @@ in
 
     services.nixosManual.browser = mkOption {
       type = types.path;
+      default = "${pkgs.w3m-nox}/bin/w3m";
       description = ''
         Browser used to show the manual.
       '';
@@ -118,8 +135,6 @@ in
     services.mingetty.helpLine = mkIf cfg.showManual
       "\nPress <Alt-F${toString cfg.ttyNumber}> for the NixOS manual.";
 
-    services.nixosManual.browser = mkDefault "${pkgs.w3m-nox}/bin/w3m";
-
   };
 
 }