2018-09-23 19:34:36 +00:00
|
|
|
{ config, lib, pkgs, baseModules, extraModules, modules, ... }:
|
2018-03-26 18:22:04 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2018-09-06 19:17:48 +00:00
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.documentation;
|
|
|
|
|
2018-09-23 19:34:36 +00:00
|
|
|
manualModules = baseModules ++ optionals cfg.nixos.includeAllModules (extraModules ++ modules);
|
|
|
|
|
2018-09-06 19:17:48 +00: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}";
|
|
|
|
options =
|
|
|
|
let
|
|
|
|
scrubbedEval = evalModules {
|
2018-09-23 19:34:36 +00:00
|
|
|
modules = [ { nixpkgs.localSystem = config.nixpkgs.localSystem; } ] ++ manualModules;
|
2018-09-06 19:17:48 +00:00
|
|
|
args = (config._module.args) // { modules = [ ]; };
|
|
|
|
specialArgs = { pkgs = scrubDerivations "pkgs" pkgs; };
|
|
|
|
};
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
helpScript = pkgs.writeScriptBin "nixos-help"
|
|
|
|
''
|
|
|
|
#! ${pkgs.runtimeShell} -e
|
|
|
|
# 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
|
|
|
|
browser="$(type -P w3m || true)"
|
|
|
|
if [ -z "$browser" ]; then
|
|
|
|
echo "$0: unable to start a web browser; please set \$BROWSER"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
exec "$browser" ${manual.manualHTMLIndex}
|
|
|
|
'';
|
|
|
|
|
|
|
|
desktopItem = pkgs.makeDesktopItem {
|
|
|
|
name = "nixos-manual";
|
|
|
|
desktopName = "NixOS Manual";
|
|
|
|
genericName = "View NixOS documentation in a web browser";
|
|
|
|
icon = "nix-snowflake";
|
|
|
|
exec = "${helpScript}/bin/nixos-help";
|
|
|
|
categories = "System";
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
2018-03-26 18:22:04 +00: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 22:20:46 +00:00
|
|
|
|
|
|
|
See "Multiple-output packages" chapter in the nixpkgs manual for more info.
|
2018-03-26 18:22:04 +00:00
|
|
|
'';
|
2018-04-05 22:20:46 +00:00
|
|
|
# which is at ../../../doc/multiple-output.xml
|
2018-03-26 18:22:04 +00: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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-04-05 22:20:46 +00:00
|
|
|
info.enable = mkOption {
|
2018-03-26 18:22:04 +00:00
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
2018-04-05 22:20:46 +00:00
|
|
|
Whether to install info pages and the <command>info</command> command.
|
|
|
|
This also includes "info" outputs.
|
2018-03-26 18:22:04 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-04-05 22:20:46 +00:00
|
|
|
doc.enable = mkOption {
|
2018-03-26 18:22:04 +00:00
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
2018-04-05 22:20:46 +00: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 18:22:04 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-04-05 22:27:46 +00: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-05 22:20:46 +00:00
|
|
|
|
2018-09-06 19:17:48 +00: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 19:34:36 +00: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>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-03-26 18:22:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
|
|
|
|
(mkIf cfg.man.enable {
|
|
|
|
environment.systemPackages = [ pkgs.man-db ];
|
|
|
|
environment.pathsToLink = [ "/share/man" ];
|
2018-05-05 08:41:28 +00:00
|
|
|
environment.extraOutputsToInstall = [ "man" ] ++ optional cfg.dev.enable "devman";
|
2019-02-06 16:30:09 +00:00
|
|
|
environment.etc."man.conf".source = "${pkgs.man-db}/etc/man_db.conf";
|
2018-03-26 18:22:04 +00:00
|
|
|
})
|
|
|
|
|
2018-04-05 22:20:46 +00:00
|
|
|
(mkIf cfg.info.enable {
|
|
|
|
environment.systemPackages = [ pkgs.texinfoInteractive ];
|
|
|
|
environment.pathsToLink = [ "/share/info" ];
|
2018-05-05 08:41:28 +00:00
|
|
|
environment.extraOutputsToInstall = [ "info" ] ++ optional cfg.dev.enable "devinfo";
|
2018-08-15 09:59:44 +00: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 01:16:50 +00:00
|
|
|
${pkgs.buildPackages.texinfo}/bin/install-info $i $out/share/info/dir
|
2018-08-15 09:59:44 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
'';
|
2018-04-05 22:20:46 +00:00
|
|
|
})
|
|
|
|
|
2018-03-26 18:22:04 +00:00
|
|
|
(mkIf cfg.doc.enable {
|
|
|
|
# TODO(@oxij): put it here and remove from profiles?
|
|
|
|
# environment.systemPackages = [ pkgs.w3m ]; # w3m-nox?
|
|
|
|
environment.pathsToLink = [ "/share/doc" ];
|
2018-05-05 08:41:28 +00:00
|
|
|
environment.extraOutputsToInstall = [ "doc" ] ++ optional cfg.dev.enable "devdoc";
|
2018-03-26 18:22:04 +00:00
|
|
|
})
|
|
|
|
|
2018-09-06 19:17:48 +00:00
|
|
|
(mkIf cfg.nixos.enable {
|
|
|
|
system.build.manual = manual;
|
|
|
|
|
|
|
|
environment.systemPackages = []
|
|
|
|
++ optional cfg.man.enable manual.manpages
|
|
|
|
++ optionals cfg.doc.enable ([ manual.manualHTML helpScript ]
|
|
|
|
++ optionals config.services.xserver.enable [ desktopItem pkgs.nixos-icons ]);
|
|
|
|
|
|
|
|
services.mingetty.helpLine = mkIf cfg.doc.enable (
|
|
|
|
"\nRun `nixos-help` "
|
|
|
|
+ optionalString config.services.nixosManual.showManual "or press <Alt-F${toString config.services.nixosManual.ttyNumber}> "
|
|
|
|
+ "for the NixOS manual."
|
|
|
|
);
|
|
|
|
})
|
|
|
|
|
2018-03-26 18:22:04 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
}
|