diff --git a/lib/modules.nix b/lib/modules.nix index 1e48f5440798..7f1646e9b8bc 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -266,6 +266,15 @@ rec { turned off. ''; }; + + _module.specialArgs = mkOption { + readOnly = true; + internal = true; + description = '' + Externally provided module arguments that can't be modified from + within a configuration, but can be used in module imports. + ''; + }; }; config = { @@ -273,6 +282,7 @@ rec { inherit extendModules; moduleType = type; }; + _module.specialArgs = specialArgs; }; }; diff --git a/nixos/modules/misc/documentation.nix b/nixos/modules/misc/documentation.nix index b031ff2f2be2..09f6d8443bbc 100644 --- a/nixos/modules/misc/documentation.nix +++ b/nixos/modules/misc/documentation.nix @@ -1,4 +1,4 @@ -{ config, options, lib, pkgs, utils, modules, baseModules, extraModules, modulesPath, ... }: +{ config, options, lib, pkgs, utils, modules, baseModules, extraModules, modulesPath, specialArgs, ... }: with lib; @@ -7,9 +7,6 @@ let cfg = config.documentation; allOpts = options; - /* Modules for which to show options even when not imported. */ - extraDocModules = [ ../virtualisation/qemu-vm.nix ]; - canCacheDocs = m: let f = import m; @@ -23,7 +20,7 @@ let docModules = let - p = partition canCacheDocs (baseModules ++ extraDocModules); + p = partition canCacheDocs (baseModules ++ cfg.nixos.extraModules); in { lazy = p.right; @@ -41,7 +38,7 @@ let modules = [ { _module.check = false; } ] ++ docModules.eager; - specialArgs = { + specialArgs = specialArgs // { pkgs = scrubDerivations "pkgs" pkgs; # allow access to arbitrary options for eager modules, eg for getting # option types from lazy modules @@ -145,6 +142,12 @@ in { imports = [ + ./man-db.nix + ./mandoc.nix + ./assertions.nix + ./meta.nix + ../config/system-path.nix + ../system/etc/etc.nix (mkRenamedOptionModule [ "programs" "info" "enable" ] [ "documentation" "info" "enable" ]) (mkRenamedOptionModule [ "programs" "man" "enable" ] [ "documentation" "man" "enable" ]) (mkRenamedOptionModule [ "services" "nixosManual" "enable" ] [ "documentation" "nixos" "enable" ]) @@ -236,6 +239,14 @@ in ''; }; + nixos.extraModules = mkOption { + type = types.listOf types.raw; + default = []; + description = '' + Modules for which to show options even when not imported. + ''; + }; + nixos.options.splitBuild = mkOption { type = types.bool; default = true; @@ -327,10 +338,6 @@ in 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." - ); }) ]); diff --git a/nixos/modules/misc/documentation/test-dummy.chapter.xml b/nixos/modules/misc/documentation/test-dummy.chapter.xml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/nixos/modules/misc/documentation/test.nix b/nixos/modules/misc/documentation/test.nix new file mode 100644 index 000000000000..1eaa63b1fb6c --- /dev/null +++ b/nixos/modules/misc/documentation/test.nix @@ -0,0 +1,49 @@ +{ nixosLib, pkgsModule, runCommand }: + +let + sys = nixosLib.evalModules rec { + modules = [ + pkgsModule + ../documentation.nix + ../version.nix + + ({ lib, someArg, ... }: { + # Make sure imports from specialArgs are respected + imports = [ someArg.myModule ]; + + # TODO test this + meta.doc = ./test-dummy.chapter.xml; + }) + + { + _module.args = { + baseModules = [ + ../documentation.nix + ../version.nix + ]; + extraModules = [ ]; + inherit modules; + }; + documentation.nixos.includeAllModules = true; + } + ]; + specialArgs.someArg.myModule = { lib, ... }: { + options.foobar = lib.mkOption { + type = lib.types.str; + description = "The foobar option was added via specialArgs"; + default = "qux"; + }; + }; + }; + +in +runCommand "documentation-check" +{ + inherit (sys.config.system.build.manual) optionsJSON; +} '' + json="$optionsJSON/share/doc/nixos/options.json" + echo checking $json + + grep 'The foobar option was added via specialArgs' <"$json" >/dev/null + touch $out +'' diff --git a/nixos/modules/misc/version.nix b/nixos/modules/misc/version.nix index bdc3e5623be6..b3cdaf5568d4 100644 --- a/nixos/modules/misc/version.nix +++ b/nixos/modules/misc/version.nix @@ -38,12 +38,19 @@ let in { imports = [ + ./label.nix (mkRenamedOptionModule [ "system" "nixosVersion" ] [ "system" "nixos" "version" ]) (mkRenamedOptionModule [ "system" "nixosVersionSuffix" ] [ "system" "nixos" "versionSuffix" ]) (mkRenamedOptionModule [ "system" "nixosRevision" ] [ "system" "nixos" "revision" ]) (mkRenamedOptionModule [ "system" "nixosLabel" ] [ "system" "nixos" "label" ]) ]; + options.boot.initrd.osRelease = mkOption { + internal = true; + readOnly = true; + default = initrdRelease; + }; + options.system = { nixos.version = mkOption { @@ -142,11 +149,6 @@ in "os-release".text = attrsToText osReleaseContents; }; - boot.initrd.systemd.contents = { - "/etc/os-release".source = initrdRelease; - "/etc/initrd-release".source = initrdRelease; - }; - # We have to use `warnings` because when warning in the default of the option # the warning would also be shown when building the manual since the manual # has to evaluate the default. diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 2c3e40ec465a..4c51210bc200 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -1287,4 +1287,5 @@ ./virtualisation/waydroid.nix ./virtualisation/xen-dom0.nix ./virtualisation/xe-guest-utilities.nix + { documentation.nixos.extraModules = [ ./virtualisation/qemu-vm.nix ]; } ] diff --git a/nixos/modules/services/ttys/getty.nix b/nixos/modules/services/ttys/getty.nix index d2bebb9c245b..e8efe72577c5 100644 --- a/nixos/modules/services/ttys/getty.nix +++ b/nixos/modules/services/ttys/getty.nix @@ -104,6 +104,7 @@ in # Note: this is set here rather than up there so that changing # nixos.label would not rebuild manual pages services.getty.greetingLine = mkDefault ''<<< Welcome to NixOS ${config.system.nixos.label} (\m) - \l >>>''; + services.getty.helpLine = mkIf (config.documentation.nixos.enable && config.documentation.doc.enable) "\nRun 'nixos-help' for the NixOS manual."; systemd.services."getty@" = { serviceConfig.ExecStart = [ diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix index 0351453a6587..888653469ed7 100644 --- a/nixos/modules/system/boot/systemd/initrd.nix +++ b/nixos/modules/system/boot/systemd/initrd.nix @@ -374,6 +374,9 @@ in { ''; "/etc/modprobe.d/debian.conf".source = pkgs.kmod-debian-aliases; + "/etc/os-release".source = config.boot.initrd.osRelease; + "/etc/initrd-release".source = config.boot.initrd.osRelease; + }; storePaths = [ diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 06210095cfce..affb179a92d3 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -127,6 +127,7 @@ in { docker-tools-cross = handleTestOn ["x86_64-linux" "aarch64-linux"] ./docker-tools-cross.nix {}; docker-tools-overlay = handleTestOn ["x86_64-linux"] ./docker-tools-overlay.nix {}; documize = handleTest ./documize.nix {}; + documentation = pkgs.callPackage ../modules/misc/documentation/test.nix { inherit nixosLib; }; doh-proxy-rust = handleTest ./doh-proxy-rust.nix {}; dokuwiki = handleTest ./dokuwiki.nix {}; domination = handleTest ./domination.nix {};