From 0f3b89bbedc1a33cc1fc3c142e235da2c64614c3 Mon Sep 17 00:00:00 2001 From: Jan Malakhovski Date: Thu, 6 Sep 2018 19:17:48 +0000 Subject: [PATCH] nixos: doc: move non-service parts of `service.nixosManual` to `documentation.nixos` --- nixos/lib/build-vms.nix | 2 +- .../cd-dvd/system-tarball-sheevaplug.nix | 2 +- nixos/modules/misc/documentation.nix | 99 +++++++++++++- .../modules/profiles/installation-device.nix | 2 +- nixos/modules/profiles/minimal.nix | 2 +- nixos/modules/rename.nix | 1 + nixos/modules/services/misc/nixos-manual.nix | 125 ++++-------------- nixos/tests/misc.nix | 2 +- 8 files changed, 126 insertions(+), 109 deletions(-) diff --git a/nixos/lib/build-vms.nix b/nixos/lib/build-vms.nix index 48288cf5962..4f65501f89c 100644 --- a/nixos/lib/build-vms.nix +++ b/nixos/lib/build-vms.nix @@ -28,7 +28,7 @@ rec { modules = configurations ++ [ ../modules/virtualisation/qemu-vm.nix ../modules/testing/test-instrumentation.nix # !!! should only get added for automated test runs - { key = "no-manual"; services.nixosManual.enable = false; } + { key = "no-manual"; documentation.nixos.enable = false; } { key = "qemu"; system.build.qemu = qemu; } ] ++ optional minimal ../modules/testing/minimal-kernel.nix; extraArgs = { inherit nodes; }; diff --git a/nixos/modules/installer/cd-dvd/system-tarball-sheevaplug.nix b/nixos/modules/installer/cd-dvd/system-tarball-sheevaplug.nix index 7ec09acd591..90a5128c02a 100644 --- a/nixos/modules/installer/cd-dvd/system-tarball-sheevaplug.nix +++ b/nixos/modules/installer/cd-dvd/system-tarball-sheevaplug.nix @@ -137,7 +137,7 @@ in # Setting vesa, we don't get the nvidia driver, which can't work in arm. services.xserver.videoDrivers = [ "vesa" ]; - services.nixosManual.enable = false; + documentation.nixos.enable = false; # Include the firmware for various wireless cards. networking.enableRalinkFirmware = true; diff --git a/nixos/modules/misc/documentation.nix b/nixos/modules/misc/documentation.nix index e6ccda5d7f4..6a7105e9cda 100644 --- a/nixos/modules/misc/documentation.nix +++ b/nixos/modules/misc/documentation.nix @@ -1,8 +1,72 @@ -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, baseModules, ... }: with lib; -let cfg = config.documentation; in +let + + cfg = config.documentation; + + /* 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}`. */ + manual = import ../../doc/manual rec { + inherit pkgs config; + version = config.system.nixos.release; + revision = "release-${version}"; + options = + let + scrubbedEval = evalModules { + modules = [ { nixpkgs.localSystem = config.nixpkgs.localSystem; } ] ++ baseModules; + 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; + }; + + helpScript = pkgs.writeScriptBin "nixos-help" + '' + #! ${pkgs.runtimeShell} -e + # Finds first executable browser in a colon-separated list. + # (see how xdg-open defines BROWSER) + browser="$( + IFS=: ; for b in $BROWSER; do + [ -n "$(type -P "$b" || true)" ] && echo "$b" && break + done + )" + 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 + exec "$browser" ${manual.manualHTMLIndex} + ''; + + desktopItem = pkgs.makeDesktopItem { + name = "nixos-manual"; + desktopName = "NixOS Manual"; + genericName = "View NixOS documentation in a web browser"; + icon = "nix-snowflake"; + exec = "${helpScript}/bin/nixos-help"; + categories = "System"; + }; + +in { @@ -66,6 +130,22 @@ let cfg = config.documentation; in ''; }; + nixos.enable = mkOption { + type = types.bool; + default = true; + description = '' + Whether to install NixOS's own documentation. + + This includes man pages like + configuration.nix + 5 if is + set. + This includes the HTML manual and the nixos-help command if + is set. + + ''; + }; + }; }; @@ -99,6 +179,21 @@ let cfg = config.documentation; in environment.extraOutputsToInstall = [ "doc" ] ++ optional cfg.dev.enable "devdoc"; }) + (mkIf cfg.nixos.enable { + system.build.manual = manual; + + environment.systemPackages = [] + ++ optional cfg.man.enable manual.manpages + ++ optionals cfg.doc.enable ([ manual.manualHTML helpScript ] + ++ optionals config.services.xserver.enable [ desktopItem pkgs.nixos-icons ]); + + services.mingetty.helpLine = mkIf cfg.doc.enable ( + "\nRun `nixos-help` " + + optionalString config.services.nixosManual.showManual "or press " + + "for the NixOS manual." + ); + }) + ]); } diff --git a/nixos/modules/profiles/installation-device.nix b/nixos/modules/profiles/installation-device.nix index ff4a23a18d0..22d1af42694 100644 --- a/nixos/modules/profiles/installation-device.nix +++ b/nixos/modules/profiles/installation-device.nix @@ -22,7 +22,7 @@ with lib; config = { # Enable in installer, even if the minimal profile disables it. - services.nixosManual.enable = mkForce true; + documentation.nixos.enable = mkForce true; # Show the manual. services.nixosManual.showManual = true; diff --git a/nixos/modules/profiles/minimal.nix b/nixos/modules/profiles/minimal.nix index ed04e46c77d..dd81e61460c 100644 --- a/nixos/modules/profiles/minimal.nix +++ b/nixos/modules/profiles/minimal.nix @@ -12,7 +12,7 @@ with lib; i18n.supportedLocales = [ (config.i18n.defaultLocale + "/UTF-8") ]; documentation.enable = mkDefault false; - services.nixosManual.enable = mkDefault false; + documentation.nixos.enable = mkDefault false; sound.enable = mkDefault false; } diff --git a/nixos/modules/rename.nix b/nixos/modules/rename.nix index 4a6bdfe83dd..bc9ff9f63dd 100644 --- a/nixos/modules/rename.nix +++ b/nixos/modules/rename.nix @@ -276,6 +276,7 @@ with lib; (mkRenamedOptionModule [ "programs" "info" "enable" ] [ "documentation" "info" "enable" ]) (mkRenamedOptionModule [ "programs" "man" "enable" ] [ "documentation" "man" "enable" ]) + (mkRenamedOptionModule [ "services" "nixosManual" "enable" ] [ "documentation" "nixos" "enable" ]) ] ++ (flip map [ "blackboxExporter" "collectdExporter" "fritzboxExporter" "jsonExporter" "minioExporter" "nginxExporter" "nodeExporter" diff --git a/nixos/modules/services/misc/nixos-manual.nix b/nixos/modules/services/misc/nixos-manual.nix index 37705e2a889..023a933fd89 100644 --- a/nixos/modules/services/misc/nixos-manual.nix +++ b/nixos/modules/services/misc/nixos-manual.nix @@ -1,89 +1,18 @@ -# 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 +# This module optionally starts a browser that shows the NixOS manual +# on one of the virtual consoles which is useful for the installation # CD. -{ config, lib, pkgs, baseModules, ... }: +{ config, lib, pkgs, ... }: with lib; -let - - cfg = config.services.nixosManual; - - /* 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}`. */ - manual = import ../../../doc/manual rec { - inherit pkgs config; - version = config.system.nixos.release; - revision = "release-${version}"; - options = - let - scrubbedEval = evalModules { - modules = [ { nixpkgs.localSystem = config.nixpkgs.localSystem; } ] ++ baseModules; - 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; - }; - - helpScript = pkgs.writeScriptBin "nixos-help" - '' - #! ${pkgs.runtimeShell} -e - # Finds first executable browser in a colon-separated list. - # (see how xdg-open defines BROWSER) - browser="$( - IFS=: ; for b in $BROWSER; do - [ -n "$(type -P "$b" || true)" ] && echo "$b" && break - done - )" - 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 - exec "$browser" ${manual.manualHTMLIndex} - ''; - - desktopItem = pkgs.makeDesktopItem { - name = "nixos-manual"; - desktopName = "NixOS Manual"; - genericName = "View NixOS documentation in a web browser"; - icon = "nix-snowflake"; - exec = "${helpScript}/bin/nixos-help"; - categories = "System"; - }; -in +let cfg = config.services.nixosManual; in { options = { - services.nixosManual.enable = mkOption { - type = types.bool; - default = true; - description = '' - Whether to build the NixOS manual pages. - ''; - }; - + # TODO(@oxij): rename this to `.enable` eventually. services.nixosManual.showManual = mkOption { type = types.bool; default = false; @@ -112,36 +41,28 @@ in }; - config = mkIf cfg.enable { + config = mkIf cfg.showManual { - system.build.manual = manual; + assertions = [{ + assertion = config.documentation.nixos.enable; + message = "Can't enable `service.nixosManual.showManual` without `documentation.nixos.enable`"; + }]; - environment.systemPackages = [] - ++ optionals config.services.xserver.enable [ desktopItem pkgs.nixos-icons ] - ++ optional config.documentation.man.enable manual.manpages - ++ optionals config.documentation.doc.enable [ manual.manualHTML helpScript ]; + boot.extraTTYs = [ "tty${toString cfg.ttyNumber}" ]; - boot.extraTTYs = mkIf cfg.showManual ["tty${toString cfg.ttyNumber}"]; - - systemd.services = optionalAttrs cfg.showManual - { "nixos-manual" = - { description = "NixOS Manual"; - wantedBy = [ "multi-user.target" ]; - serviceConfig = - { ExecStart = "${cfg.browser} ${manual.manualHTMLIndex}"; - StandardInput = "tty"; - StandardOutput = "tty"; - TTYPath = "/dev/tty${toString cfg.ttyNumber}"; - TTYReset = true; - TTYVTDisallocate = true; - Restart = "always"; - }; - }; + systemd.services."nixos-manual" = { + description = "NixOS Manual"; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = "${cfg.browser} ${config.system.build.manual.manualHTMLIndex}"; + StandardInput = "tty"; + StandardOutput = "tty"; + TTYPath = "/dev/tty${toString cfg.ttyNumber}"; + TTYReset = true; + TTYVTDisallocate = true; + Restart = "always"; }; - - services.mingetty.helpLine = "\nRun `nixos-help` " - + lib.optionalString cfg.showManual "or press " - + "for the NixOS manual."; + }; }; diff --git a/nixos/tests/misc.nix b/nixos/tests/misc.nix index b0bc1d083b1..6d72ac997f8 100644 --- a/nixos/tests/misc.nix +++ b/nixos/tests/misc.nix @@ -14,7 +14,7 @@ import ./make-test.nix ({ pkgs, ...} : rec { { swapDevices = mkOverride 0 [ { device = "/root/swapfile"; size = 128; } ]; environment.variables.EDITOR = mkOverride 0 "emacs"; - services.nixosManual.enable = mkOverride 0 true; + documentation.nixos.enable = mkOverride 0 true; systemd.tmpfiles.rules = [ "d /tmp 1777 root root 10d" ]; fileSystems = mkVMOverride { "/tmp2" = { fsType = "tmpfs";