1 # make sure to use NON EXISTING kernel settings else they may conflict with
6 lts_kernel = pkgs.linuxPackages.kernel;
8 # to see the result once the module transformed the lose structured config
9 getConfig = structuredConfig:
10 (lts_kernel.override {
11 structuredExtraConfig = structuredConfig;
12 }).configfile.structuredConfig;
14 mandatoryVsOptionalConfig = lib.mkMerge [
15 { NIXOS_FAKE_USB_DEBUG = lib.kernel.yes;}
16 { NIXOS_FAKE_USB_DEBUG = lib.kernel.option lib.kernel.yes; }
19 freeformConfig = lib.mkMerge [
20 { NIXOS_FAKE_MMC_BLOCK_MINORS = lib.kernel.freeform "32"; } # same as default, won't trigger any error
21 { NIXOS_FAKE_MMC_BLOCK_MINORS = lib.kernel.freeform "64"; } # will trigger an error but the message is not great:
24 mkDefaultWorksConfig = lib.mkMerge [
25 { "NIXOS_TEST_BOOLEAN" = lib.kernel.yes; }
26 { "NIXOS_TEST_BOOLEAN" = lib.mkDefault lib.kernel.no; }
29 allOptionalRemainOptional = lib.mkMerge [
30 { NIXOS_FAKE_USB_DEBUG = lib.kernel.option lib.kernel.yes;}
31 { NIXOS_FAKE_USB_DEBUG = lib.kernel.option lib.kernel.yes;}
34 failures = lib.runTests {
36 expr = (getConfig { NIXOS_FAKE_USB_DEBUG = lib.kernel.yes;}).NIXOS_FAKE_USB_DEBUG;
37 expected = { tristate = "y"; optional = false; freeform = null; };
40 # mandatory flag should win over optional
41 testMandatoryCheck = {
42 expr = (getConfig mandatoryVsOptionalConfig).NIXOS_FAKE_USB_DEBUG.optional;
47 expr = (getConfig mkDefaultWorksConfig)."NIXOS_TEST_BOOLEAN".tristate;
51 testAllOptionalRemainOptional = {
52 expr = (getConfig allOptionalRemainOptional)."NIXOS_FAKE_USB_DEBUG".optional;
56 # check that freeform options are unique
58 # > The option `settings.NIXOS_FAKE_MMC_BLOCK_MINORS.freeform' has conflicting definitions, in `<unknown-file>' and `<unknown-file>'
60 res = builtins.tryEval ( (getConfig freeformConfig).NIXOS_FAKE_MMC_BLOCK_MINORS.freeform);
69 lib.optional (failures != [])
70 (throw "The following kernel unit tests failed: ${lib.generators.toPretty {} failures}")