2021-12-02 18:19:56 +00:00
|
|
|
{ config, lib, pkgs, extendModules, noUserModules, ... }:
|
2018-03-26 19:22:04 +01:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2018-09-06 20:17:48 +01:00
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.documentation;
|
|
|
|
|
2021-12-02 18:19:56 +00:00
|
|
|
/* Modules for which to show options even when not imported. */
|
|
|
|
extraDocModules = [ ../virtualisation/qemu-vm.nix ];
|
2018-09-23 20:34:36 +01:00
|
|
|
|
2018-09-06 20:17:48 +01: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 01:29:30 +00:00
|
|
|
extraSources = cfg.nixos.extraModuleSources;
|
2018-09-06 20:17:48 +01:00
|
|
|
options =
|
|
|
|
let
|
2021-12-02 18:19:56 +00:00
|
|
|
extendNixOS = if cfg.nixos.includeAllModules then extendModules else noUserModules.extendModules;
|
|
|
|
scrubbedEval = extendNixOS {
|
|
|
|
modules = extraDocModules;
|
|
|
|
specialArgs.pkgs = scrubDerivations "pkgs" pkgs;
|
2018-09-06 20:17:48 +01: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 10:51:02 +00:00
|
|
|
|
|
|
|
nixos-help = let
|
|
|
|
helpScript = pkgs.writeShellScriptBin "nixos-help" ''
|
2018-09-06 20:17:48 +01: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 16:20:19 +01:00
|
|
|
browser="${pkgs.w3m-nographics}/bin/w3m"
|
2018-09-06 20:17:48 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
exec "$browser" ${manual.manualHTMLIndex}
|
|
|
|
'';
|
|
|
|
|
2020-11-05 10:51:02 +00: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 20:17:48 +01:00
|
|
|
|
|
|
|
in
|
2018-03-26 19:22:04 +01:00
|
|
|
|
|
|
|
{
|
2019-12-10 01:51:19 +00: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 19:22:04 +01: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-05 23:20:46 +01:00
|
|
|
|
|
|
|
See "Multiple-output packages" chapter in the nixpkgs manual for more info.
|
2018-03-26 19:22:04 +01:00
|
|
|
'';
|
2021-02-21 06:16:37 +00:00
|
|
|
# which is at ../../../doc/multiple-output.chapter.md
|
2018-03-26 19:22:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
man.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
2021-09-24 18:20:23 +01:00
|
|
|
Whether to install manual pages.
|
|
|
|
This also includes <literal>man</literal> outputs.
|
2018-03-26 19:22:04 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-05-01 17:48:39 +01:00
|
|
|
man.generateCaches = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2021-09-24 18:20:23 +01:00
|
|
|
Whether to generate the manual page index caches.
|
|
|
|
This allows searching for a page or
|
2021-09-24 18:31:03 +01:00
|
|
|
keyword using utilities like
|
|
|
|
<citerefentry>
|
|
|
|
<refentrytitle>apropos</refentrytitle>
|
|
|
|
<manvolnum>1</manvolnum>
|
|
|
|
</citerefentry>
|
|
|
|
and the <literal>-k</literal> option of
|
|
|
|
<citerefentry>
|
|
|
|
<refentrytitle>man</refentrytitle>
|
|
|
|
<manvolnum>1</manvolnum>
|
|
|
|
</citerefentry>.
|
2020-05-01 17:48:39 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-04-05 23:20:46 +01:00
|
|
|
info.enable = mkOption {
|
2018-03-26 19:22:04 +01:00
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
2018-04-05 23:20:46 +01:00
|
|
|
Whether to install info pages and the <command>info</command> command.
|
|
|
|
This also includes "info" outputs.
|
2018-03-26 19:22:04 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-04-05 23:20:46 +01:00
|
|
|
doc.enable = mkOption {
|
2018-03-26 19:22:04 +01:00
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
2018-04-05 23:20:46 +01: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 19:22:04 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-04-05 23:27:46 +01:00
|
|
|
dev.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to install documentation targeted at developers.
|
|
|
|
<itemizedlist>
|
2021-09-15 21:43:44 +01:00
|
|
|
<listitem><para>This includes man pages targeted at developers if <option>documentation.man.enable</option> is
|
2018-04-05 23:27:46 +01:00
|
|
|
set (this also includes "devman" outputs).</para></listitem>
|
2021-09-15 21:43:44 +01:00
|
|
|
<listitem><para>This includes info pages targeted at developers if <option>documentation.info.enable</option>
|
2018-04-05 23:27:46 +01:00
|
|
|
is set (this also includes "devinfo" outputs).</para></listitem>
|
2021-09-15 21:43:44 +01:00
|
|
|
<listitem><para>This includes other pages targeted at developers if <option>documentation.doc.enable</option>
|
2018-04-05 23:27:46 +01:00
|
|
|
is set (this also includes "devdoc" outputs).</para></listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
'';
|
|
|
|
};
|
2018-04-05 23:20:46 +01:00
|
|
|
|
2018-09-06 20:17:48 +01: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>
|
2021-09-15 21:43:44 +01:00
|
|
|
<manvolnum>5</manvolnum></citerefentry> if <option>documentation.man.enable</option> is
|
2018-09-06 20:17:48 +01:00
|
|
|
set.</para></listitem>
|
|
|
|
<listitem><para>This includes the HTML manual and the <command>nixos-help</command> command if
|
2021-09-15 21:43:44 +01:00
|
|
|
<option>documentation.doc.enable</option> is set.</para></listitem>
|
2018-09-06 20:17:48 +01:00
|
|
|
</itemizedlist>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-09-23 20:34:36 +01: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 01:29:30 +00: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.
|
|
|
|
'';
|
2021-10-03 17:06:03 +01:00
|
|
|
example = literalExpression ''
|
2019-11-13 01:29:30 +00:00
|
|
|
# e.g. with options from modules in ''${pkgs.customModules}/nix:
|
|
|
|
[ pkgs.customModules ]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-03-26 19:22:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
|
2021-09-24 18:20:23 +01:00
|
|
|
# The actual implementation for this lives in man-db.nix
|
2018-03-26 19:22:04 +01:00
|
|
|
(mkIf cfg.man.enable {
|
|
|
|
environment.pathsToLink = [ "/share/man" ];
|
2021-09-24 18:20:23 +01:00
|
|
|
environment.extraOutputsToInstall = [ "man" ] ++ optional cfg.dev.enable "devman";
|
2018-03-26 19:22:04 +01:00
|
|
|
})
|
|
|
|
|
2018-04-05 23:20:46 +01:00
|
|
|
(mkIf cfg.info.enable {
|
|
|
|
environment.systemPackages = [ pkgs.texinfoInteractive ];
|
|
|
|
environment.pathsToLink = [ "/share/info" ];
|
2018-05-05 09:41:28 +01:00
|
|
|
environment.extraOutputsToInstall = [ "info" ] ++ optional cfg.dev.enable "devinfo";
|
2018-08-15 10:59:44 +01: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 02:16:50 +01:00
|
|
|
${pkgs.buildPackages.texinfo}/bin/install-info $i $out/share/info/dir
|
2018-08-15 10:59:44 +01:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
'';
|
2018-04-05 23:20:46 +01:00
|
|
|
})
|
|
|
|
|
2018-03-26 19:22:04 +01:00
|
|
|
(mkIf cfg.doc.enable {
|
|
|
|
environment.pathsToLink = [ "/share/doc" ];
|
2018-05-05 09:41:28 +01:00
|
|
|
environment.extraOutputsToInstall = [ "doc" ] ++ optional cfg.dev.enable "devdoc";
|
2018-03-26 19:22:04 +01:00
|
|
|
})
|
|
|
|
|
2018-09-06 20:17:48 +01:00
|
|
|
(mkIf cfg.nixos.enable {
|
|
|
|
system.build.manual = manual;
|
|
|
|
|
|
|
|
environment.systemPackages = []
|
|
|
|
++ optional cfg.man.enable manual.manpages
|
2021-07-24 05:50:01 +01:00
|
|
|
++ optionals cfg.doc.enable [ manual.manualHTML nixos-help ];
|
2018-09-06 20:17:48 +01:00
|
|
|
|
2021-01-05 08:25:53 +00:00
|
|
|
services.getty.helpLine = mkIf cfg.doc.enable (
|
2020-03-23 09:29:12 +00:00
|
|
|
"\nRun 'nixos-help' for the NixOS manual."
|
2018-09-06 20:17:48 +01:00
|
|
|
);
|
|
|
|
})
|
|
|
|
|
2018-03-26 19:22:04 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
}
|