3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/nixos/modules/services/misc/nixos-manual.nix

122 lines
2.9 KiB
Nix
Raw Normal View History

# 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.
{ config, lib, pkgs, baseModules, ... }:
with lib;
let
cfg = config.services.nixosManual;
versionModule =
{ system.nixosVersionSuffix = config.system.nixosVersionSuffix;
system.nixosRevision = config.system.nixosRevision;
nixpkgs.system = config.nixpkgs.system;
};
2013-10-28 14:48:20 +00:00
eval = evalModules {
modules = [ versionModule ] ++ baseModules;
args = (config._module.args) // { modules = [ ]; };
2013-10-28 14:48:20 +00:00
};
manual = import ../../../doc/manual {
inherit pkgs;
version = config.system.nixosVersion;
revision = config.system.nixosRevision;
2013-10-28 14:48:20 +00:00
options = eval.options;
};
entry = "${manual.manual}/share/doc/nixos/index.html";
help = pkgs.writeScriptBin "nixos-help"
''
#! ${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
fi
2013-08-20 12:55:39 +01:00
exec "$browser" ${entry}
'';
in
{
options = {
services.nixosManual.enable = mkOption {
type = types.bool;
2013-10-30 16:37:45 +00:00
default = true;
description = ''
Whether to build the NixOS manual pages.
'';
};
services.nixosManual.showManual = mkOption {
2013-10-30 16:37:45 +00:00
type = types.bool;
default = false;
description = ''
Whether to show the NixOS manual on one of the virtual
consoles.
'';
};
services.nixosManual.ttyNumber = mkOption {
default = "8";
description = ''
Virtual console on which to show the manual.
'';
};
services.nixosManual.browser = mkOption {
2013-10-30 16:37:45 +00:00
type = types.path;
default = "${pkgs.w3m}/bin/w3m";
description = ''
Browser used to show the manual.
'';
};
};
config = mkIf cfg.enable {
system.build.manual = manual;
environment.systemPackages = [ manual.manpages help ];
boot.extraTTYs = mkIf cfg.showManual ["tty${cfg.ttyNumber}"];
systemd.services = optionalAttrs cfg.showManual
{ "nixos-manual" =
{ description = "NixOS Manual";
wantedBy = [ "multi-user.target" ];
serviceConfig =
{ ExecStart = "${cfg.browser} ${entry}";
StandardInput = "tty";
StandardOutput = "tty";
TTYPath = "/dev/tty${cfg.ttyNumber}";
TTYReset = true;
TTYVTDisallocate = true;
Restart = "always";
};
};
};
services.mingetty.helpLine = mkIf cfg.showManual
"\nPress <Alt-F${toString cfg.ttyNumber}> for the NixOS manual.";
};
}