at 18.03-beta 4.2 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 /* For the purpose of generating docs, evaluate options with each derivation 15 in `pkgs` (recursively) replaced by a fake with path "\${pkgs.attribute.path}". 16 It isn't perfect, but it seems to cover a vast majority of use cases. 17 Caveat: even if the package is reached by a different means, 18 the path above will be shown and not e.g. `${config.services.foo.package}`. */ 19 manual = import ../../../doc/manual rec { 20 inherit pkgs config; 21 version = config.system.nixos.release; 22 revision = "release-${version}"; 23 options = 24 let 25 scrubbedEval = evalModules { 26 modules = [ { nixpkgs.system = config.nixpkgs.system; } ] ++ baseModules; 27 args = (config._module.args) // { modules = [ ]; }; 28 specialArgs = { pkgs = scrubDerivations "pkgs" pkgs; }; 29 }; 30 scrubDerivations = namePrefix: pkgSet: mapAttrs 31 (name: value: 32 let wholeName = "${namePrefix}.${name}"; in 33 if isAttrs value then 34 scrubDerivations wholeName value 35 // (optionalAttrs (isDerivation value) { outPath = "\${${wholeName}}"; }) 36 else value 37 ) 38 pkgSet; 39 in scrubbedEval.options; 40 }; 41 42 entry = "${manual.manual}/share/doc/nixos/index.html"; 43 44 helpScript = pkgs.writeScriptBin "nixos-help" 45 '' 46 #! ${pkgs.stdenv.shell} -e 47 browser="$BROWSER" 48 if [ -z "$browser" ]; then 49 browser="$(type -P xdg-open || true)" 50 if [ -z "$browser" ]; then 51 browser="$(type -P w3m || true)" 52 if [ -z "$browser" ]; then 53 echo "$0: unable to start a web browser; please set \$BROWSER" 54 exit 1 55 fi 56 fi 57 fi 58 exec "$browser" ${entry} 59 ''; 60 61 desktopItem = pkgs.makeDesktopItem { 62 name = "nixos-manual"; 63 desktopName = "NixOS Manual"; 64 genericName = "View NixOS documentation in a web browser"; 65 icon = "nix-snowflake"; 66 exec = "${helpScript}/bin/nixos-help"; 67 categories = "System"; 68 }; 69in 70 71{ 72 73 options = { 74 75 services.nixosManual.enable = mkOption { 76 type = types.bool; 77 default = true; 78 description = '' 79 Whether to build the NixOS manual pages. 80 ''; 81 }; 82 83 services.nixosManual.showManual = mkOption { 84 type = types.bool; 85 default = false; 86 description = '' 87 Whether to show the NixOS manual on one of the virtual 88 consoles. 89 ''; 90 }; 91 92 services.nixosManual.ttyNumber = mkOption { 93 type = types.int; 94 default = 8; 95 description = '' 96 Virtual console on which to show the manual. 97 ''; 98 }; 99 100 services.nixosManual.browser = mkOption { 101 type = types.path; 102 default = "${pkgs.w3m-nox}/bin/w3m"; 103 description = '' 104 Browser used to show the manual. 105 ''; 106 }; 107 108 }; 109 110 111 config = mkIf cfg.enable { 112 113 system.build.manual = manual; 114 115 environment.systemPackages = 116 [ manual.manual helpScript ] 117 ++ optionals config.services.xserver.enable [desktopItem pkgs.nixos-icons] 118 ++ optional config.programs.man.enable manual.manpages; 119 120 boot.extraTTYs = mkIf cfg.showManual ["tty${toString cfg.ttyNumber}"]; 121 122 systemd.services = optionalAttrs cfg.showManual 123 { "nixos-manual" = 124 { description = "NixOS Manual"; 125 wantedBy = [ "multi-user.target" ]; 126 serviceConfig = 127 { ExecStart = "${cfg.browser} ${entry}"; 128 StandardInput = "tty"; 129 StandardOutput = "tty"; 130 TTYPath = "/dev/tty${toString cfg.ttyNumber}"; 131 TTYReset = true; 132 TTYVTDisallocate = true; 133 Restart = "always"; 134 }; 135 }; 136 }; 137 138 services.mingetty.helpLine = "\nRun `nixos-help` " 139 + lib.optionalString cfg.showManual "or press <Alt-F${toString cfg.ttyNumber}> " 140 + "for the NixOS manual."; 141 142 }; 143 144}