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