summary refs log tree commit diff
path: root/nixos/modules/misc
diff options
context:
space:
mode:
authorrnhmjoj <rnhmjoj@inventati.org>2020-05-01 18:48:39 +0200
committerrnhmjoj <rnhmjoj@inventati.org>2020-06-18 10:17:04 +0200
commitedc6a76cc025ef972979dad6692e0fd5d5cfcbbb (patch)
treea7f8fa70cfcb860208c379be0cebafc50a265f94 /nixos/modules/misc
parentdfff485819775fd6ddbf922351ea381bb4b657d2 (diff)
downloadnixpkgs-edc6a76cc025ef972979dad6692e0fd5d5cfcbbb.tar
nixpkgs-edc6a76cc025ef972979dad6692e0fd5d5cfcbbb.tar.gz
nixpkgs-edc6a76cc025ef972979dad6692e0fd5d5cfcbbb.tar.bz2
nixpkgs-edc6a76cc025ef972979dad6692e0fd5d5cfcbbb.tar.lz
nixpkgs-edc6a76cc025ef972979dad6692e0fd5d5cfcbbb.tar.xz
nixpkgs-edc6a76cc025ef972979dad6692e0fd5d5cfcbbb.tar.zst
nixpkgs-edc6a76cc025ef972979dad6692e0fd5d5cfcbbb.zip
nixos/documentation: add option to generate caches
Previously the NixOS-specific configuration for man-db was in the
package itself and /etc/man.conf was completely ignored.
This change moves it to /etc/man_db.conf, making declarative
configuration practical again.

It's now possible to generate the mandb caches for all packages
installed through NixOS `environment.systemPackages` at build-time.
The standard location for the stateful cache (/var/cache/man) is also
configured to allow users to run `mandb` manually if they wish.

Since generating the cache can be expensive the option is off by
default.
Diffstat (limited to 'nixos/modules/misc')
-rw-r--r--nixos/modules/misc/documentation.nix38
1 files changed, 37 insertions, 1 deletions
diff --git a/nixos/modules/misc/documentation.nix b/nixos/modules/misc/documentation.nix
index 7ad4be9a02e..71a40b4f4d6 100644
--- a/nixos/modules/misc/documentation.nix
+++ b/nixos/modules/misc/documentation.nix
@@ -102,6 +102,16 @@ in
         '';
       };
 
+      man.generateCaches = mkOption {
+        type = types.bool;
+        default = false;
+        description = ''
+          Whether to generate the manual page index caches using
+          <literal>mandb(8)</literal>. This allows searching for a page or
+          keyword using utilities like <literal>apropos(1)</literal>.
+        '';
+      };
+
       info.enable = mkOption {
         type = types.bool;
         default = true;
@@ -187,7 +197,33 @@ in
       environment.systemPackages = [ pkgs.man-db ];
       environment.pathsToLink = [ "/share/man" ];
       environment.extraOutputsToInstall = [ "man" ] ++ optional cfg.dev.enable "devman";
-      environment.etc."man.conf".source = "${pkgs.man-db}/etc/man_db.conf";
+      environment.etc."man_db.conf".text =
+        let
+          manualPages = pkgs.buildEnv {
+            name = "man-paths";
+            paths = config.environment.systemPackages;
+            pathsToLink = [ "/share/man" ];
+            extraOutputsToInstall = ["man"];
+            ignoreCollisions = true;
+          };
+          manualCache = pkgs.runCommandLocal "man-cache" { }
+          ''
+            echo "MANDB_MAP ${manualPages}/share/man $out" > man.conf
+            ${pkgs.man-db}/bin/mandb -C man.conf -psc
+          '';
+        in
+        ''
+          # Manual pages paths for NixOS
+          MANPATH_MAP /run/current-system/sw/bin /run/current-system/sw/share/man
+          MANPATH_MAP /run/wrappers/bin          /run/current-system/sw/share/man
+
+          ${optionalString cfg.man.generateCaches ''
+          # Generated manual pages cache for NixOS (immutable)
+          MANDB_MAP /run/current-system/sw/share/man ${manualCache}
+          ''}
+          # Manual pages caches for NixOS
+          MANDB_MAP /run/current-system/sw/share/man /var/cache/man/nixos
+        '';
     })
 
     (mkIf cfg.info.enable {