1 { config, pkgs, lib, ... }:
4 cfg = config.documentation.man.man-db;
9 documentation.man.man-db = {
10 enable = lib.mkEnableOption "man-db as the default man page viewer" // {
11 default = config.documentation.man.enable;
12 defaultText = lib.literalExpression "config.documentation.man.enable";
16 skipPackages = lib.mkOption {
17 type = lib.types.listOf lib.types.package;
21 Packages to *not* include in the man-db.
22 This can be useful to avoid unnecessary rebuilds due to packages that change frequently, like nixos-version.
26 manualPages = lib.mkOption {
27 type = lib.types.path;
28 default = pkgs.buildEnv {
30 paths = lib.subtractLists cfg.skipPackages config.environment.systemPackages;
31 pathsToLink = [ "/share/man" ];
32 extraOutputsToInstall = [ "man" ]
33 ++ lib.optionals config.documentation.dev.enable [ "devman" ];
34 ignoreCollisions = true;
36 defaultText = lib.literalMD "all man pages in {option}`config.environment.systemPackages`";
38 The manual pages to generate caches for if {option}`documentation.man.generateCaches`
39 is enabled. Must be a path to a directory with man pages under
40 `/share/man`; see the source for an example.
41 Advanced users can make this a content-addressed derivation to save a few rebuilds.
45 package = lib.mkOption {
46 type = lib.types.package;
47 default = pkgs.man-db;
48 defaultText = lib.literalExpression "pkgs.man-db";
50 The `man-db` derivation to use. Useful to override
51 configuration options used for the package.
58 (lib.mkRenamedOptionModule [ "documentation" "man" "manualPages" ] [ "documentation" "man" "man-db" "manualPages" ])
61 config = lib.mkIf cfg.enable {
62 environment.systemPackages = [ cfg.package ];
63 environment.etc."man_db.conf".text =
65 manualCache = pkgs.runCommand "man-cache" {
66 nativeBuildInputs = [ cfg.package ];
68 echo "MANDB_MAP ${cfg.manualPages}/share/man $out" > man.conf
69 mandb -C man.conf -psc >/dev/null 2>&1
73 # Manual pages paths for NixOS
74 MANPATH_MAP /run/current-system/sw/bin /run/current-system/sw/share/man
75 MANPATH_MAP /run/wrappers/bin /run/current-system/sw/share/man
77 ${lib.optionalString config.documentation.man.generateCaches ''
78 # Generated manual pages cache for NixOS (immutable)
79 MANDB_MAP /run/current-system/sw/share/man ${manualCache}
81 # Manual pages caches for NixOS
82 MANDB_MAP /run/current-system/sw/share/man /var/cache/man/nixos