2020-01-03 02:54:05 +01:00
|
|
|
{ config, lib, pkgs, baseModules, extraModules, modules, modulesPath, ... }:
|
2018-03-26 20:22:04 +02:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2018-09-06 21:17:48 +02:00
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.documentation;
|
|
|
|
|
2018-09-23 21:34:36 +02:00
|
|
|
manualModules = baseModules ++ optionals cfg.nixos.includeAllModules (extraModules ++ modules);
|
|
|
|
|
2018-09-06 21:17:48 +02:00
|
|
|
/* For the purpose of generating docs, evaluate options with each derivation
|
|
|
|
in `pkgs` (recursively) replaced by a fake with path "\${pkgs.attribute.path}".
|
|
|
|
It isn't perfect, but it seems to cover a vast majority of use cases.
|
|
|
|
Caveat: even if the package is reached by a different means,
|
|
|
|
the path above will be shown and not e.g. `${config.services.foo.package}`. */
|
|
|
|
manual = import ../../doc/manual rec {
|
|
|
|
inherit pkgs config;
|
|
|
|
version = config.system.nixos.release;
|
|
|
|
revision = "release-${version}";
|
2019-11-13 02:29:30 +01:00
|
|
|
extraSources = cfg.nixos.extraModuleSources;
|
2018-09-06 21:17:48 +02:00
|
|
|
options =
|
|
|
|
let
|
|
|
|
scrubbedEval = evalModules {
|
2018-09-23 21:34:36 +02:00
|
|
|
modules = [ { nixpkgs.localSystem = config.nixpkgs.localSystem; } ] ++ manualModules;
|
2018-09-06 21:17:48 +02:00
|
|
|
args = (config._module.args) // { modules = [ ]; };
|
2020-01-03 02:54:05 +01:00
|
|
|
specialArgs = {
|
|
|
|
pkgs = scrubDerivations "pkgs" pkgs;
|
|
|
|
inherit modulesPath;
|
|
|
|
};
|
2018-09-06 21:17:48 +02:00
|
|
|
};
|
|
|
|
scrubDerivations = namePrefix: pkgSet: mapAttrs
|
|
|
|
(name: value:
|
|
|
|
let wholeName = "${namePrefix}.${name}"; in
|
|
|
|
if isAttrs value then
|
|
|
|
scrubDerivations wholeName value
|
|
|
|
// (optionalAttrs (isDerivation value) { outPath = "\${${wholeName}}"; })
|
|
|
|
else value
|
|
|
|
)
|
|
|
|
pkgSet;
|
|
|
|
in scrubbedEval.options;
|
|
|
|
};
|
|
|
|
|
2020-11-05 11:51:02 +01:00
|
|
|
|
|
|
|
nixos-help = let
|
|
|
|
helpScript = pkgs.writeShellScriptBin "nixos-help" ''
|
2018-09-06 21:17:48 +02:00
|
|
|
# Finds first executable browser in a colon-separated list.
|
|
|
|
# (see how xdg-open defines BROWSER)
|
|
|
|
browser="$(
|
|
|
|
IFS=: ; for b in $BROWSER; do
|
|
|
|
[ -n "$(type -P "$b" || true)" ] && echo "$b" && break
|
|
|
|
done
|
|
|
|
)"
|
|
|
|
if [ -z "$browser" ]; then
|
|
|
|
browser="$(type -P xdg-open || true)"
|
|
|
|
if [ -z "$browser" ]; then
|
2019-06-01 17:20:19 +02:00
|
|
|
browser="${pkgs.w3m-nographics}/bin/w3m"
|
2018-09-06 21:17:48 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
exec "$browser" ${manual.manualHTMLIndex}
|
|
|
|
'';
|
|
|
|
|
2020-11-05 11:51:02 +01:00
|
|
|
desktopItem = pkgs.makeDesktopItem {
|
|
|
|
name = "nixos-manual";
|
|
|
|
desktopName = "NixOS Manual";
|
|
|
|
genericName = "View NixOS documentation in a web browser";
|
|
|
|
icon = "nix-snowflake";
|
|
|
|
exec = "nixos-help";
|
|
|
|
categories = "System";
|
|
|
|
};
|
|
|
|
|
|
|
|
in pkgs.symlinkJoin {
|
|
|
|
name = "nixos-help";
|
|
|
|
paths = [
|
|
|
|
helpScript
|
|
|
|
desktopItem
|
|
|
|
];
|
|
|
|
};
|
2018-09-06 21:17:48 +02:00
|
|
|
|
|
|
|
in
|
2018-03-26 20:22:04 +02:00
|
|
|
|
|
|
|
{
|
2019-12-10 02:51:19 +01:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "programs" "info" "enable" ] [ "documentation" "info" "enable" ])
|
|
|
|
(mkRenamedOptionModule [ "programs" "man" "enable" ] [ "documentation" "man" "enable" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "nixosManual" "enable" ] [ "documentation" "nixos" "enable" ])
|
|
|
|
];
|
2018-03-26 20:22:04 +02:00
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
documentation = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to install documentation of packages from
|
|
|
|
<option>environment.systemPackages</option> into the generated system path.
|
2018-04-06 00:20:46 +02:00
|
|
|
|
|
|
|
See "Multiple-output packages" chapter in the nixpkgs manual for more info.
|
2018-03-26 20:22:04 +02:00
|
|
|
'';
|
2021-02-21 07:16:37 +01:00
|
|
|
# which is at ../../../doc/multiple-output.chapter.md
|
2018-03-26 20:22:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
man.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to install manual pages and the <command>man</command> command.
|
|
|
|
This also includes "man" outputs.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-05-01 18:48:39 +02:00
|
|
|
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>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-04-06 00:20:46 +02:00
|
|
|
info.enable = mkOption {
|
2018-03-26 20:22:04 +02:00
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
2018-04-06 00:20:46 +02:00
|
|
|
Whether to install info pages and the <command>info</command> command.
|
|
|
|
This also includes "info" outputs.
|
2018-03-26 20:22:04 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-04-06 00:20:46 +02:00
|
|
|
doc.enable = mkOption {
|
2018-03-26 20:22:04 +02:00
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
2018-04-06 00:20:46 +02:00
|
|
|
Whether to install documentation distributed in packages' <literal>/share/doc</literal>.
|
|
|
|
Usually plain text and/or HTML.
|
|
|
|
This also includes "doc" outputs.
|
2018-03-26 20:22:04 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-04-06 00:27:46 +02:00
|
|
|
dev.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to install documentation targeted at developers.
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem><para>This includes man pages targeted at developers if <option>man.enable</option> is
|
|
|
|
set (this also includes "devman" outputs).</para></listitem>
|
|
|
|
<listitem><para>This includes info pages targeted at developers if <option>info.enable</option>
|
|
|
|
is set (this also includes "devinfo" outputs).</para></listitem>
|
|
|
|
<listitem><para>This includes other pages targeted at developers if <option>doc.enable</option>
|
|
|
|
is set (this also includes "devdoc" outputs).</para></listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
'';
|
|
|
|
};
|
2018-04-06 00:20:46 +02:00
|
|
|
|
2018-09-06 21:17:48 +02:00
|
|
|
nixos.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to install NixOS's own documentation.
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem><para>This includes man pages like
|
|
|
|
<citerefentry><refentrytitle>configuration.nix</refentrytitle>
|
|
|
|
<manvolnum>5</manvolnum></citerefentry> if <option>man.enable</option> is
|
|
|
|
set.</para></listitem>
|
|
|
|
<listitem><para>This includes the HTML manual and the <command>nixos-help</command> command if
|
|
|
|
<option>doc.enable</option> is set.</para></listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-09-23 21:34:36 +02:00
|
|
|
nixos.includeAllModules = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether the generated NixOS's documentation should include documentation for all
|
|
|
|
the options from all the NixOS modules included in the current
|
|
|
|
<literal>configuration.nix</literal>. Disabling this will make the manual
|
|
|
|
generator to ignore options defined outside of <literal>baseModules</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-11-13 02:29:30 +01:00
|
|
|
nixos.extraModuleSources = mkOption {
|
|
|
|
type = types.listOf (types.either types.path types.str);
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Which extra NixOS module paths the generated NixOS's documentation should strip
|
|
|
|
from options.
|
|
|
|
'';
|
|
|
|
example = literalExample ''
|
|
|
|
# e.g. with options from modules in ''${pkgs.customModules}/nix:
|
|
|
|
[ pkgs.customModules ]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-03-26 20:22:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
|
|
|
|
(mkIf cfg.man.enable {
|
|
|
|
environment.systemPackages = [ pkgs.man-db ];
|
|
|
|
environment.pathsToLink = [ "/share/man" ];
|
2018-05-05 10:41:28 +02:00
|
|
|
environment.extraOutputsToInstall = [ "man" ] ++ optional cfg.dev.enable "devman";
|
2020-05-01 18:48:39 +02:00
|
|
|
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
|
2020-12-03 21:57:09 +01:00
|
|
|
${pkgs.man-db}/bin/mandb -C man.conf -psc >/dev/null 2>&1
|
2020-05-01 18:48:39 +02:00
|
|
|
'';
|
|
|
|
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
|
|
|
|
'';
|
2018-03-26 20:22:04 +02:00
|
|
|
})
|
|
|
|
|
2018-04-06 00:20:46 +02:00
|
|
|
(mkIf cfg.info.enable {
|
|
|
|
environment.systemPackages = [ pkgs.texinfoInteractive ];
|
|
|
|
environment.pathsToLink = [ "/share/info" ];
|
2018-05-05 10:41:28 +02:00
|
|
|
environment.extraOutputsToInstall = [ "info" ] ++ optional cfg.dev.enable "devinfo";
|
2018-08-15 11:59:44 +02:00
|
|
|
environment.extraSetup = ''
|
|
|
|
if [ -w $out/share/info ]; then
|
|
|
|
shopt -s nullglob
|
|
|
|
for i in $out/share/info/*.info $out/share/info/*.info.gz; do
|
2018-10-12 03:16:50 +02:00
|
|
|
${pkgs.buildPackages.texinfo}/bin/install-info $i $out/share/info/dir
|
2018-08-15 11:59:44 +02:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
'';
|
2018-04-06 00:20:46 +02:00
|
|
|
})
|
|
|
|
|
2018-03-26 20:22:04 +02:00
|
|
|
(mkIf cfg.doc.enable {
|
|
|
|
environment.pathsToLink = [ "/share/doc" ];
|
2018-05-05 10:41:28 +02:00
|
|
|
environment.extraOutputsToInstall = [ "doc" ] ++ optional cfg.dev.enable "devdoc";
|
2018-03-26 20:22:04 +02:00
|
|
|
})
|
|
|
|
|
2018-09-06 21:17:48 +02:00
|
|
|
(mkIf cfg.nixos.enable {
|
|
|
|
system.build.manual = manual;
|
|
|
|
|
|
|
|
environment.systemPackages = []
|
|
|
|
++ optional cfg.man.enable manual.manpages
|
2020-11-05 11:51:02 +01:00
|
|
|
++ optionals cfg.doc.enable ([ manual.manualHTML nixos-help ]
|
|
|
|
++ optionals config.services.xserver.enable [ pkgs.nixos-icons ]);
|
2018-09-06 21:17:48 +02:00
|
|
|
|
2021-01-05 09:25:53 +01:00
|
|
|
services.getty.helpLine = mkIf cfg.doc.enable (
|
2020-03-23 10:29:12 +01:00
|
|
|
"\nRun 'nixos-help' for the NixOS manual."
|
2018-09-06 21:17:48 +02:00
|
|
|
);
|
|
|
|
})
|
|
|
|
|
2018-03-26 20:22:04 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
}
|