at 15.09-beta 3.0 kB view raw
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 versionModule = 15 { system.nixosVersionSuffix = config.system.nixosVersionSuffix; 16 system.nixosRevision = config.system.nixosRevision; 17 nixpkgs.system = config.nixpkgs.system; 18 }; 19 20 eval = evalModules { 21 modules = [ versionModule ] ++ baseModules; 22 args = (config._module.args) // { modules = [ ]; }; 23 }; 24 25 manual = import ../../../doc/manual { 26 inherit pkgs; 27 version = config.system.nixosVersion; 28 revision = config.system.nixosRevision; 29 options = eval.options; 30 }; 31 32 entry = "${manual.manual}/share/doc/nixos/index.html"; 33 34 help = pkgs.writeScriptBin "nixos-help" 35 '' 36 #! ${pkgs.stdenv.shell} -e 37 browser="$BROWSER" 38 if [ -z "$browser" ]; then 39 browser="$(type -P xdg-open || true)" 40 if [ -z "$browser" ]; then 41 browser="$(type -P w3m || true)" 42 if [ -z "$browser" ]; then 43 echo "$0: unable to start a web browser; please set \$BROWSER" 44 exit 1 45 fi 46 fi 47 fi 48 exec "$browser" ${entry} 49 ''; 50 51in 52 53{ 54 55 options = { 56 57 services.nixosManual.enable = mkOption { 58 type = types.bool; 59 default = true; 60 description = '' 61 Whether to build the NixOS manual pages. 62 ''; 63 }; 64 65 services.nixosManual.showManual = mkOption { 66 type = types.bool; 67 default = false; 68 description = '' 69 Whether to show the NixOS manual on one of the virtual 70 consoles. 71 ''; 72 }; 73 74 services.nixosManual.ttyNumber = mkOption { 75 default = "8"; 76 description = '' 77 Virtual console on which to show the manual. 78 ''; 79 }; 80 81 services.nixosManual.browser = mkOption { 82 type = types.path; 83 default = "${pkgs.w3m}/bin/w3m"; 84 description = '' 85 Browser used to show the manual. 86 ''; 87 }; 88 89 }; 90 91 92 config = mkIf cfg.enable { 93 94 system.build.manual = manual; 95 96 environment.systemPackages = [ manual.manpages help ]; 97 98 boot.extraTTYs = mkIf cfg.showManual ["tty${cfg.ttyNumber}"]; 99 100 systemd.services = optionalAttrs cfg.showManual 101 { "nixos-manual" = 102 { description = "NixOS Manual"; 103 wantedBy = [ "multi-user.target" ]; 104 serviceConfig = 105 { ExecStart = "${cfg.browser} ${entry}"; 106 StandardInput = "tty"; 107 StandardOutput = "tty"; 108 TTYPath = "/dev/tty${cfg.ttyNumber}"; 109 TTYReset = true; 110 TTYVTDisallocate = true; 111 Restart = "always"; 112 }; 113 }; 114 }; 115 116 services.mingetty.helpLine = mkIf cfg.showManual 117 "\nPress <Alt-F${toString cfg.ttyNumber}> for the NixOS manual."; 118 119 }; 120 121}