{ config, lib, pkgs, extendModules, noUserModules, ... }: with lib; let cfg = config.documentation; /* Modules for which to show options even when not imported. */ extraDocModules = [ ../virtualisation/qemu-vm.nix ]; /* 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}"; extraSources = cfg.nixos.extraModuleSources; options = let extendNixOS = if cfg.nixos.includeAllModules then extendModules else noUserModules.extendModules; scrubbedEval = extendNixOS { modules = extraDocModules; 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; }; nixos-help = let helpScript = pkgs.writeShellScriptBin "nixos-help" '' # 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="${pkgs.w3m-nographics}/bin/w3m" 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 = "nixos-help"; categories = "System"; }; in pkgs.symlinkJoin { name = "nixos-help"; paths = [ helpScript desktopItem ]; }; in { imports = [ (mkRenamedOptionModule [ "programs" "info" "enable" ] [ "documentation" "info" "enable" ]) (mkRenamedOptionModule [ "programs" "man" "enable" ] [ "documentation" "man" "enable" ]) (mkRenamedOptionModule [ "services" "nixosManual" "enable" ] [ "documentation" "nixos" "enable" ]) ]; options = { documentation = { enable = mkOption { type = types.bool; default = true; description = '' Whether to install documentation of packages from into the generated system path. See "Multiple-output packages" chapter in the nixpkgs manual for more info. ''; # which is at ../../../doc/multiple-output.chapter.md }; man.enable = mkOption { type = types.bool; default = true; description = '' Whether to install manual pages. This also includes man outputs. ''; }; man.generateCaches = mkOption { type = types.bool; default = false; description = '' Whether to generate the manual page index caches. This allows searching for a page or keyword using utilities like apropos(1). ''; }; info.enable = mkOption { type = types.bool; default = true; description = '' Whether to install info pages and the info command. This also includes "info" outputs. ''; }; doc.enable = mkOption { type = types.bool; default = true; description = '' Whether to install documentation distributed in packages' /share/doc. Usually plain text and/or HTML. This also includes "doc" outputs. ''; }; dev.enable = mkOption { type = types.bool; default = false; description = '' Whether to install documentation targeted at developers. This includes man pages targeted at developers if is set (this also includes "devman" outputs). This includes info pages targeted at developers if is set (this also includes "devinfo" outputs). This includes other pages targeted at developers if is set (this also includes "devdoc" outputs). ''; }; 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. ''; }; nixos.includeAllModules = mkOption { type = types.bool; default = false; description = '' Whether the generated NixOS's documentation should include documentation for all the options from all the NixOS modules included in the current configuration.nix. Disabling this will make the manual generator to ignore options defined outside of baseModules. ''; }; nixos.extraModuleSources = mkOption { type = types.listOf (types.either types.path types.str); default = [ ]; description = '' Which extra NixOS module paths the generated NixOS's documentation should strip from options. ''; example = literalExpression '' # e.g. with options from modules in ''${pkgs.customModules}/nix: [ pkgs.customModules ] ''; }; }; }; config = mkIf cfg.enable (mkMerge [ # The actual implementation for this lives in man-db.nix (mkIf cfg.man.enable { environment.pathsToLink = [ "/share/man" ]; environment.extraOutputsToInstall = [ "man" ] ++ optional cfg.dev.enable "devman"; }) (mkIf cfg.info.enable { environment.systemPackages = [ pkgs.texinfoInteractive ]; environment.pathsToLink = [ "/share/info" ]; environment.extraOutputsToInstall = [ "info" ] ++ optional cfg.dev.enable "devinfo"; environment.extraSetup = '' if [ -w $out/share/info ]; then shopt -s nullglob for i in $out/share/info/*.info $out/share/info/*.info.gz; do ${pkgs.buildPackages.texinfo}/bin/install-info $i $out/share/info/dir done fi ''; }) (mkIf cfg.doc.enable { environment.pathsToLink = [ "/share/doc" ]; 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 nixos-help ]; services.getty.helpLine = mkIf cfg.doc.enable ( "\nRun 'nixos-help' for the NixOS manual." ); }) ]); }