2009-07-14 17:27:46 +01:00
|
|
|
# This module includes the NixOS man-pages in the system environment,
|
|
|
|
# and optionally starts a browser that shows the NixOS manual on one
|
|
|
|
# of the virtual consoles. The latter is useful for the installation
|
|
|
|
# CD.
|
2009-01-08 23:30:23 +00:00
|
|
|
|
2014-05-05 20:18:53 +01:00
|
|
|
{ config, lib, pkgs, baseModules, ... }:
|
2009-01-08 23:30:23 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2009-04-14 13:31:08 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
let
|
2009-01-08 23:30:23 +00:00
|
|
|
|
2009-07-14 17:27:46 +01:00
|
|
|
cfg = config.services.nixosManual;
|
2009-01-08 23:30:23 +00:00
|
|
|
|
2016-02-03 12:19: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}`. */
|
2017-04-01 01:00:00 +01:00
|
|
|
manual = import ../../../doc/manual rec {
|
2016-04-27 13:29:33 +01:00
|
|
|
inherit pkgs config;
|
2017-04-01 01:00:00 +01:00
|
|
|
version = config.system.nixos.release;
|
|
|
|
revision = "release-${version}";
|
2016-02-03 12:19:48 +00:00
|
|
|
options =
|
|
|
|
let
|
|
|
|
scrubbedEval = evalModules {
|
2018-04-05 20:22:45 +01:00
|
|
|
modules = [ { nixpkgs.localSystem = config.nixpkgs.localSystem; } ] ++ baseModules;
|
2016-02-03 12:19: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;
|
2009-09-18 16:27:10 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2017-03-13 20:53:54 +00:00
|
|
|
helpScript = pkgs.writeScriptBin "nixos-help"
|
2013-01-08 01:13:33 +00:00
|
|
|
''
|
2018-03-01 19:38:53 +00:00
|
|
|
#! ${pkgs.runtimeShell} -e
|
2018-09-01 18:42:47 +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
|
|
|
|
)"
|
2013-08-20 12:55:39 +01:00
|
|
|
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
|
2013-01-08 01:13:33 +00:00
|
|
|
fi
|
2018-09-06 20:17:44 +01:00
|
|
|
exec "$browser" ${manual.manualHTMLIndex}
|
2013-01-08 01:13:33 +00:00
|
|
|
'';
|
|
|
|
|
2017-03-13 20:53:54 +00:00
|
|
|
desktopItem = pkgs.makeDesktopItem {
|
|
|
|
name = "nixos-manual";
|
|
|
|
desktopName = "NixOS Manual";
|
|
|
|
genericName = "View NixOS documentation in a web browser";
|
2017-03-16 21:48:09 +00:00
|
|
|
icon = "nix-snowflake";
|
2017-03-13 20:53:54 +00:00
|
|
|
exec = "${helpScript}/bin/nixos-help";
|
|
|
|
categories = "System";
|
|
|
|
};
|
2009-07-14 17:27:46 +01:00
|
|
|
in
|
2009-04-14 13:31:08 +01:00
|
|
|
|
2009-07-14 17:27:46 +01:00
|
|
|
{
|
2009-04-14 13:31:08 +01:00
|
|
|
|
2009-07-14 17:27:46 +01:00
|
|
|
options = {
|
2009-01-08 23:30:23 +00:00
|
|
|
|
2009-07-14 17:27:46 +01:00
|
|
|
services.nixosManual.enable = mkOption {
|
2012-06-04 15:35:48 +01:00
|
|
|
type = types.bool;
|
2013-10-30 16:37:45 +00:00
|
|
|
default = true;
|
2009-07-14 17:27:46 +01:00
|
|
|
description = ''
|
|
|
|
Whether to build the NixOS manual pages.
|
|
|
|
'';
|
|
|
|
};
|
2009-04-14 13:31:08 +01:00
|
|
|
|
2009-07-14 17:27:46 +01:00
|
|
|
services.nixosManual.showManual = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.bool;
|
2014-03-17 11:45:57 +00:00
|
|
|
default = false;
|
2009-07-14 17:27:46 +01:00
|
|
|
description = ''
|
|
|
|
Whether to show the NixOS manual on one of the virtual
|
|
|
|
consoles.
|
2009-01-08 23:30:23 +00:00
|
|
|
'';
|
2009-07-14 17:27:46 +01:00
|
|
|
};
|
2009-04-14 13:31:08 +01:00
|
|
|
|
2009-07-14 17:27:46 +01:00
|
|
|
services.nixosManual.ttyNumber = mkOption {
|
2016-02-21 20:26:07 +00:00
|
|
|
type = types.int;
|
|
|
|
default = 8;
|
2009-07-14 17:27:46 +01:00
|
|
|
description = ''
|
|
|
|
Virtual console on which to show the manual.
|
|
|
|
'';
|
2009-01-08 23:30:23 +00:00
|
|
|
};
|
2009-04-14 13:31:08 +01:00
|
|
|
|
2009-07-14 17:27:46 +01:00
|
|
|
services.nixosManual.browser = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.path;
|
2018-05-23 22:55:05 +01:00
|
|
|
default = "${pkgs.w3m-nographics}/bin/w3m";
|
2009-07-14 17:27:46 +01:00
|
|
|
description = ''
|
|
|
|
Browser used to show the manual.
|
|
|
|
'';
|
2009-01-08 23:30:23 +00:00
|
|
|
};
|
2009-04-14 13:31:08 +01:00
|
|
|
|
2009-01-08 23:30:23 +00:00
|
|
|
};
|
2009-07-14 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2009-10-05 14:55:33 +01:00
|
|
|
system.build.manual = manual;
|
|
|
|
|
2018-03-26 19:22:04 +01:00
|
|
|
environment.systemPackages = []
|
|
|
|
++ optionals config.services.xserver.enable [ desktopItem pkgs.nixos-icons ]
|
|
|
|
++ optional config.documentation.man.enable manual.manpages
|
2018-09-06 20:17:44 +01:00
|
|
|
++ optionals config.documentation.doc.enable [ manual.manualHTML helpScript ];
|
2009-07-14 17:27:46 +01:00
|
|
|
|
2016-02-21 20:26:07 +00:00
|
|
|
boot.extraTTYs = mkIf cfg.showManual ["tty${toString cfg.ttyNumber}"];
|
2009-07-14 17:27:46 +01:00
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
systemd.services = optionalAttrs cfg.showManual
|
2012-10-04 21:15:10 +01:00
|
|
|
{ "nixos-manual" =
|
|
|
|
{ description = "NixOS Manual";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig =
|
2018-09-06 20:17:44 +01:00
|
|
|
{ ExecStart = "${cfg.browser} ${manual.manualHTMLIndex}";
|
2012-10-04 21:15:10 +01:00
|
|
|
StandardInput = "tty";
|
|
|
|
StandardOutput = "tty";
|
2016-02-21 20:26:07 +00:00
|
|
|
TTYPath = "/dev/tty${toString cfg.ttyNumber}";
|
2012-10-04 21:15:10 +01:00
|
|
|
TTYReset = true;
|
|
|
|
TTYVTDisallocate = true;
|
|
|
|
Restart = "always";
|
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
|
|
|
};
|
2009-07-14 17:27:46 +01:00
|
|
|
|
2017-10-25 10:13:33 +01:00
|
|
|
services.mingetty.helpLine = "\nRun `nixos-help` "
|
|
|
|
+ lib.optionalString cfg.showManual "or press <Alt-F${toString cfg.ttyNumber}> "
|
|
|
|
+ "for the NixOS manual.";
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-07-14 17:27:46 +01:00
|
|
|
};
|
|
|
|
|
2009-01-08 23:30:23 +00:00
|
|
|
}
|