Merge pull request #181222 from hercules-ci/module-specialArgs

`_module.specialArgs` + unit test for nixos/documentation module
This commit is contained in:
Robert Hensing 2022-08-08 11:53:10 +02:00 committed by GitHub
commit 661c29c806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 89 additions and 15 deletions

View File

@ -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;
};
};

View File

@ -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."
);
})
]);

View File

@ -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
''

View File

@ -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.

View File

@ -1287,4 +1287,5 @@
./virtualisation/waydroid.nix
./virtualisation/xen-dom0.nix
./virtualisation/xe-guest-utilities.nix
{ documentation.nixos.extraModules = [ ./virtualisation/qemu-vm.nix ]; }
]

View File

@ -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 = [

View File

@ -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 = [

View File

@ -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 {};