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}`. */
|
2009-09-18 16:27:10 +01:00
|
|
|
manual = import ../../../doc/manual {
|
2016-04-27 13:29:33 +01:00
|
|
|
inherit pkgs config;
|
2016-07-28 17:27:03 +01:00
|
|
|
version = config.system.nixosRelease;
|
|
|
|
revision = "release-${config.system.nixosRelease}";
|
2016-02-03 12:19:48 +00:00
|
|
|
options =
|
|
|
|
let
|
|
|
|
scrubbedEval = evalModules {
|
2016-07-28 17:27:03 +01: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 16:27:10 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2014-08-27 10:08:26 +01: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
|
|
|
''
|
|
|
|
#! ${pkgs.stdenv.shell} -e
|
2013-08-20 12:55:39 +01: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 12:55:39 +01: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 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;
|
2016-01-13 10:48:11 +00:00
|
|
|
default = "${pkgs.w3m-nox}/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;
|
|
|
|
|
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 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 =
|
2013-01-08 01:13:33 +00:00
|
|
|
{ ExecStart = "${cfg.browser} ${entry}";
|
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
|
|
|
|
|
|
|
services.mingetty.helpLine = mkIf cfg.showManual
|
|
|
|
"\nPress <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
|
|
|
}
|