mirror of
https://github.com/nix-community/home-manager.git
synced 2024-12-15 17:50:53 +00:00
man: add mandoc and man-db options
This change affects the way home-manager generates index file of man pages.
This commit is contained in:
parent
1e22ef1518
commit
8eb33ea4e6
3 changed files with 91 additions and 32 deletions
|
@ -1,9 +1,11 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
{ config, lib, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let cfg = config.programs.man;
|
||||
in {
|
||||
imports = [ ./man/man-db.nix ./man/mandoc.nix ];
|
||||
|
||||
options = {
|
||||
programs.man = {
|
||||
enable = mkOption {
|
||||
|
@ -18,8 +20,6 @@ in {
|
|||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.man;
|
||||
defaultText = literalExpression "pkgs.man";
|
||||
description = "The man package to use.";
|
||||
};
|
||||
|
||||
|
@ -41,36 +41,14 @@ in {
|
|||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
assertions = [{
|
||||
assertion = !(cfg.mandoc.enable && cfg.man-db.enable);
|
||||
message = ''
|
||||
man-db and mandoc can't be used as the man page viewer at the same time!
|
||||
'';
|
||||
}];
|
||||
|
||||
home.packages = [ cfg.package ];
|
||||
home.extraOutputsToInstall = [ "man" ];
|
||||
|
||||
# This is mostly copy/pasted/adapted from NixOS' documentation.nix.
|
||||
home.file = mkIf cfg.generateCaches {
|
||||
".manpath".text = let
|
||||
# Generate a directory containing installed packages' manpages.
|
||||
manualPages = pkgs.buildEnv {
|
||||
name = "man-paths";
|
||||
paths = config.home.packages;
|
||||
pathsToLink = [ "/share/man" ];
|
||||
extraOutputsToInstall = [ "man" ];
|
||||
ignoreCollisions = true;
|
||||
};
|
||||
|
||||
# Generate a database of all manpages in ${manualPages}.
|
||||
manualCache = pkgs.runCommandLocal "man-cache" {
|
||||
nativeBuildInputs = [ cfg.package ];
|
||||
} ''
|
||||
# Generate a temporary man.conf so mandb knows where to
|
||||
# write cache files.
|
||||
echo "MANDB_MAP ${manualPages}/share/man $out" > man.conf
|
||||
|
||||
# Run mandb to generate cache files:
|
||||
mandb -C man.conf --no-straycats --create \
|
||||
${manualPages}/share/man
|
||||
'';
|
||||
in ''
|
||||
MANDB_MAP ${config.home.profileDirectory}/share/man ${manualCache}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
47
modules/programs/man/man-db.nix
Normal file
47
modules/programs/man/man-db.nix
Normal file
|
@ -0,0 +1,47 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let cfg = config.programs.man;
|
||||
in {
|
||||
options.programs.man.man-db.enable = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether to enable man-db as the man page viewer.
|
||||
'';
|
||||
};
|
||||
|
||||
config = mkIf cfg.man-db.enable {
|
||||
programs.man.package = mkDefault pkgs.man;
|
||||
|
||||
# This is mostly copy/pasted/adapted from NixOS' documentation.nix.
|
||||
home.file = mkIf cfg.generateCaches {
|
||||
".manpath".text = let
|
||||
# Generate a directory containing installed packages' manpages.
|
||||
manualPages = pkgs.buildEnv {
|
||||
name = "man-paths";
|
||||
paths = config.home.packages;
|
||||
pathsToLink = [ "/share/man" ];
|
||||
extraOutputsToInstall = [ "man" ];
|
||||
ignoreCollisions = true;
|
||||
};
|
||||
|
||||
# Generate a database of all manpages in ${manualPages}.
|
||||
manualCache = pkgs.runCommandLocal "man-cache" {
|
||||
nativeBuildInputs = [ cfg.package ];
|
||||
} ''
|
||||
# Generate a temporary man.conf so mandb knows where to
|
||||
# write cache files.
|
||||
echo "MANDB_MAP ${manualPages}/share/man $out" > man.conf
|
||||
|
||||
# Run mandb to generate cache files:
|
||||
mandb -C man.conf --no-straycats --create \
|
||||
${manualPages}/share/man
|
||||
'';
|
||||
in ''
|
||||
MANDB_MAP ${config.home.profileDirectory}/share/man ${manualCache}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
34
modules/programs/man/mandoc.nix
Normal file
34
modules/programs/man/mandoc.nix
Normal file
|
@ -0,0 +1,34 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let cfg = config.programs.man;
|
||||
in {
|
||||
options.programs.man.mandoc.enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to enable mandoc as the man page viewer.
|
||||
'';
|
||||
};
|
||||
|
||||
config = mkIf cfg.mandoc.enable (mkMerge [
|
||||
{ programs.man.package = mkDefault pkgs.mandoc; }
|
||||
(mkIf cfg.generateCaches {
|
||||
home.activation.generateMandocDB = hm.dag.entryAfter [ "writeBoundary" ]
|
||||
(let
|
||||
makewhatis = "${getBin cfg.package}/bin/makewhatis";
|
||||
|
||||
manualPages = pkgs.buildEnv {
|
||||
name = "man-paths";
|
||||
paths = config.home.packages;
|
||||
pathsToLink = [ "/share/man" ];
|
||||
extraOutputsToInstall = [ "man" ];
|
||||
ignoreCollisions = true;
|
||||
};
|
||||
in ''
|
||||
${makewhatis} ''${DRY_RUN:+-n} ''${VERBOSE:+-Dp} -T utf8 ${manualPages} 2>&1
|
||||
'');
|
||||
})
|
||||
]);
|
||||
}
|
Loading…
Reference in a new issue