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