1{ lib, pkgs }:
2
3with lib.kernel;
4with lib.asserts;
5with lib.modules;
6
7# To test nixos/modules/system/boot/kernel_config.nix;
8let
9 # copied from release-lib.nix
10 assertTrue = bool:
11 if bool
12 then pkgs.runCommand "evaluated-to-true" {} "touch $out"
13 else pkgs.runCommand "evaluated-to-false" {} "false";
14
15 lts_kernel = pkgs.linuxPackages.kernel;
16
17 kernelTestConfig = structuredConfig: (lts_kernel.override {
18 structuredExtraConfig = structuredConfig;
19 }).configfile.structuredConfig;
20
21 mandatoryVsOptionalConfig = mkMerge [
22 { USB_DEBUG = option yes;}
23 { USB_DEBUG = yes;}
24 ];
25
26 freeformConfig = mkMerge [
27 { MMC_BLOCK_MINORS = freeform "32"; } # same as default, won't trigger any error
28 { MMC_BLOCK_MINORS = freeform "64"; } # will trigger an error but the message is not great:
29 ];
30
31 yesWinsOverNoConfig = mkMerge [
32 # default for "8139TOO_PIO" is no
33 { "8139TOO_PIO" = yes; } # yes wins over no by default
34 { "8139TOO_PIO" = no; }
35 ];
36in
37{
38 # mandatory flag should win over optional
39 mandatoryCheck = (kernelTestConfig mandatoryVsOptionalConfig);
40
41 # check that freeform options are unique
42 # Should trigger
43 # > The option `settings.MMC_BLOCK_MINORS.freeform' has conflicting definitions, in `<unknown-file>' and `<unknown-file>'
44 freeformCheck = let
45 res = builtins.tryEval ( (kernelTestConfig freeformConfig).MMC_BLOCK_MINORS.freeform);
46 in
47 assertTrue (res.success == false);
48
49 yesVsNoCheck = let
50 res = kernelTestConfig yesWinsOverNoConfig;
51 in
52 assertTrue (res."8139TOO_PIO".tristate == "y");
53}