fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Yurekaman: fix caches generation in cross-compiled system (#4294)4542db60

master
2.3 KiB76 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let cfg = config.programs.man;
6in {
7  options = {
8    programs.man = {
9      enable = mkOption {
10        type = types.bool;
11        default = true;
12        description = ''
13          Whether to enable manual pages and the {command}`man`
14          command. This also includes "man" outputs of all
15          `home.packages`.
16        '';
17      };
18
19      package = mkOption {
20        type = types.package;
21        default = pkgs.man;
22        defaultText = literalExpression "pkgs.man";
23        description = "The man package to use.";
24      };
25
26      generateCaches = mkOption {
27        type = types.bool;
28        default = false;
29        description = ''
30          Whether to generate the manual page index caches using
31          {manpage}`mandb(8)`. This allows searching for a page or
32          keyword using utilities like {manpage}`apropos(1)`.
33
34          This feature is disabled by default because it slows down
35          building. If you don't mind waiting a few more seconds when
36          Home Manager builds a new generation, you may safely enable
37          this option.
38        '';
39      };
40    };
41  };
42
43  config = mkIf cfg.enable {
44    home.packages = [ cfg.package ];
45    home.extraOutputsToInstall = [ "man" ];
46
47    # This is mostly copy/pasted/adapted from NixOS' documentation.nix.
48    home.file = mkIf cfg.generateCaches {
49      ".manpath".text = let
50        # Generate a directory containing installed packages' manpages.
51        manualPages = pkgs.buildEnv {
52          name = "man-paths";
53          paths = config.home.packages;
54          pathsToLink = [ "/share/man" ];
55          extraOutputsToInstall = [ "man" ];
56          ignoreCollisions = true;
57        };
58
59        # Generate a database of all manpages in ${manualPages}.
60        manualCache = pkgs.runCommandLocal "man-cache" {
61          nativeBuildInputs = [ cfg.package ];
62        } ''
63          # Generate a temporary man.conf so mandb knows where to
64          # write cache files.
65          echo "MANDB_MAP ${manualPages}/share/man $out" > man.conf
66
67          # Run mandb to generate cache files:
68          mandb -C man.conf --no-straycats --create \
69            ${manualPages}/share/man
70        '';
71      in ''
72        MANDB_MAP ${config.home.profileDirectory}/share/man ${manualCache}
73      '';
74    };
75  };
76}