From 6a3d020b9054980c1ee2fc6171a6a1d6c210d4e0 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Fri, 24 Sep 2021 19:20:23 +0200 Subject: [PATCH] nixos/documentation: move man-db-specifics into new man-db module It may be possible to revert the move of `documentation.man.manualPages` later. The problem is that other man implementations (mandoc) want to generate their index databases in place, so the approach taken here doesn't translate super well. --- nixos/modules/misc/documentation.nix | 53 +++-------------------- nixos/modules/misc/man-db.nix | 63 ++++++++++++++++++++++++++++ nixos/modules/module-list.nix | 2 + 3 files changed, 71 insertions(+), 47 deletions(-) create mode 100644 nixos/modules/misc/man-db.nix diff --git a/nixos/modules/misc/documentation.nix b/nixos/modules/misc/documentation.nix index 64b1c15086fc..d107a1abbc56 100644 --- a/nixos/modules/misc/documentation.nix +++ b/nixos/modules/misc/documentation.nix @@ -74,10 +74,6 @@ let ]; }; - # list of man outputs currently active intended for use as default values - # for man-related options, thus "man" is included unconditionally. - activeManOutputs = [ "man" ] ++ lib.optionals cfg.dev.enable [ "devman" ]; - in { @@ -107,8 +103,8 @@ in type = types.bool; default = true; description = '' - Whether to install manual pages and the man command. - This also includes "man" outputs. + Whether to install manual pages. + This also includes man outputs. ''; }; @@ -116,30 +112,12 @@ in type = types.bool; default = false; description = '' - Whether to generate the manual page index caches using - mandb(8). This allows searching for a page or + Whether to generate the manual page index caches. + This allows searching for a page or keyword using utilities like apropos(1). ''; }; - man.manualPages = mkOption { - type = types.path; - default = pkgs.buildEnv { - name = "man-paths"; - paths = config.environment.systemPackages; - pathsToLink = [ "/share/man" ]; - extraOutputsToInstall = activeManOutputs; - ignoreCollisions = true; - }; - defaultText = literalDocBook "all man pages in "; - description = '' - The manual pages to generate caches for if - is enabled. Must be a path to a directory with man pages under - /share/man; see the source for an example. - Advanced users can make this a content-addressed derivation to save a few rebuilds. - ''; - }; - info.enable = mkOption { type = types.bool; default = true; @@ -221,29 +199,10 @@ in config = mkIf cfg.enable (mkMerge [ + # The actual implementation for this lives in man-db.nix (mkIf cfg.man.enable { - environment.systemPackages = [ pkgs.man-db ]; environment.pathsToLink = [ "/share/man" ]; - environment.extraOutputsToInstall = activeManOutputs; - environment.etc."man_db.conf".text = - let - manualCache = pkgs.runCommandLocal "man-cache" { } '' - echo "MANDB_MAP ${cfg.man.manualPages}/share/man $out" > man.conf - ${pkgs.man-db}/bin/mandb -C man.conf -psc >/dev/null 2>&1 - ''; - 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 - ''; + environment.extraOutputsToInstall = [ "man" ] ++ optional cfg.dev.enable "devman"; }) (mkIf cfg.info.enable { diff --git a/nixos/modules/misc/man-db.nix b/nixos/modules/misc/man-db.nix new file mode 100644 index 000000000000..94898504b3f7 --- /dev/null +++ b/nixos/modules/misc/man-db.nix @@ -0,0 +1,63 @@ +{ config, pkgs, lib, ... }: + +let + cfg = config.documentation.man.man-db; +in + +{ + options = { + documentation.man.man-db = { + enable = lib.mkEnableOption "man-db as the default man page viewer" // { + default = config.documentation.man.enable; + defaultText = lib.literalExpression "config.documentation.man.enable"; + example = false; + }; + + manualPages = lib.mkOption { + type = lib.types.path; + default = pkgs.buildEnv { + name = "man-paths"; + paths = config.environment.systemPackages; + pathsToLink = [ "/share/man" ]; + extraOutputsToInstall = [ "man" ] + ++ lib.optionals config.documentation.dev.enable [ "devman" ]; + ignoreCollisions = true; + }; + defaultText = lib.literalDocBook "all man pages in "; + description = '' + The manual pages to generate caches for if + is enabled. Must be a path to a directory with man pages under + /share/man; see the source for an example. + Advanced users can make this a content-addressed derivation to save a few rebuilds. + ''; + }; + }; + }; + + imports = [ + (lib.mkRenamedOptionModule [ "documentation" "man" "manualPages" ] [ "documentation" "man" "man-db" "manualPages" ]) + ]; + + config = lib.mkIf cfg.enable { + environment.systemPackages = [ pkgs.man-db ]; + environment.etc."man_db.conf".text = + let + manualCache = pkgs.runCommandLocal "man-cache" { } '' + echo "MANDB_MAP ${cfg.manualPages}/share/man $out" > man.conf + ${pkgs.man-db}/bin/mandb -C man.conf -psc >/dev/null 2>&1 + ''; + 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 + + ${lib.optionalString config.documentation.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 + ''; + }; +} diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index dd6a74df30cb..6fe6b41c6098 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -108,6 +108,8 @@ ./misc/lib.nix ./misc/label.nix ./misc/locate.nix + ./misc/man-db.nix + ./misc/mandoc.nix ./misc/meta.nix ./misc/nixpkgs.nix ./misc/passthru.nix