1# This module includes the NixOS man-pages in the system environment,
2# and optionally starts a browser that shows the NixOS manual on one
3# of the virtual consoles. The latter is useful for the installation
4# CD.
5
6{ config, lib, pkgs, baseModules, ... }:
7
8with lib;
9
10let
11
12 cfg = config.services.nixosManual;
13
14 /* For the purpose of generating docs, evaluate options with each derivation
15 in `pkgs` (recursively) replaced by a fake with path "\${pkgs.attribute.path}".
16 It isn't perfect, but it seems to cover a vast majority of use cases.
17 Caveat: even if the package is reached by a different means,
18 the path above will be shown and not e.g. `${config.services.foo.package}`. */
19 manual = import ../../../doc/manual {
20 inherit pkgs config;
21 version = config.system.nixosRelease;
22 revision = "release-${config.system.nixosRelease}";
23 options =
24 let
25 scrubbedEval = evalModules {
26 modules = [ { nixpkgs.system = config.nixpkgs.system; } ] ++ baseModules;
27 args = (config._module.args) // { modules = [ ]; };
28 specialArgs = { pkgs = scrubDerivations "pkgs" pkgs; };
29 };
30 scrubDerivations = namePrefix: pkgSet: mapAttrs
31 (name: value:
32 let wholeName = "${namePrefix}.${name}"; in
33 if isAttrs value then
34 scrubDerivations wholeName value
35 // (optionalAttrs (isDerivation value) { outPath = "\${${wholeName}}"; })
36 else value
37 )
38 pkgSet;
39 in scrubbedEval.options;
40 };
41
42 entry = "${manual.manual}/share/doc/nixos/index.html";
43
44 help = pkgs.writeScriptBin "nixos-help"
45 ''
46 #! ${pkgs.stdenv.shell} -e
47 browser="$BROWSER"
48 if [ -z "$browser" ]; then
49 browser="$(type -P xdg-open || true)"
50 if [ -z "$browser" ]; then
51 browser="$(type -P w3m || true)"
52 if [ -z "$browser" ]; then
53 echo "$0: unable to start a web browser; please set \$BROWSER"
54 exit 1
55 fi
56 fi
57 fi
58 exec "$browser" ${entry}
59 '';
60
61in
62
63{
64
65 options = {
66
67 services.nixosManual.enable = mkOption {
68 type = types.bool;
69 default = true;
70 description = ''
71 Whether to build the NixOS manual pages.
72 '';
73 };
74
75 services.nixosManual.showManual = mkOption {
76 type = types.bool;
77 default = false;
78 description = ''
79 Whether to show the NixOS manual on one of the virtual
80 consoles.
81 '';
82 };
83
84 services.nixosManual.ttyNumber = mkOption {
85 type = types.int;
86 default = 8;
87 description = ''
88 Virtual console on which to show the manual.
89 '';
90 };
91
92 services.nixosManual.browser = mkOption {
93 type = types.path;
94 default = "${pkgs.w3m-nox}/bin/w3m";
95 description = ''
96 Browser used to show the manual.
97 '';
98 };
99
100 };
101
102
103 config = mkIf cfg.enable {
104
105 system.build.manual = manual;
106
107 environment.systemPackages =
108 [ manual.manual help ]
109 ++ optional config.programs.man.enable manual.manpages;
110
111 boot.extraTTYs = mkIf cfg.showManual ["tty${toString cfg.ttyNumber}"];
112
113 systemd.services = optionalAttrs cfg.showManual
114 { "nixos-manual" =
115 { description = "NixOS Manual";
116 wantedBy = [ "multi-user.target" ];
117 serviceConfig =
118 { ExecStart = "${cfg.browser} ${entry}";
119 StandardInput = "tty";
120 StandardOutput = "tty";
121 TTYPath = "/dev/tty${toString cfg.ttyNumber}";
122 TTYReset = true;
123 TTYVTDisallocate = true;
124 Restart = "always";
125 };
126 };
127 };
128
129 services.mingetty.helpLine = mkIf cfg.showManual
130 "\nPress <Alt-F${toString cfg.ttyNumber}> for the NixOS manual.";
131
132 };
133
134}