Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at fix-function-merge 73 lines 2.2 kB view raw
1# make sure to use NON EXISTING kernel settings else they may conflict with 2# common-config.nix 3{ lib, pkgs }: 4 5with lib; 6with kernel; 7 8let 9 lts_kernel = pkgs.linuxPackages.kernel; 10 11 # to see the result once the module transformed the lose structured config 12 getConfig = structuredConfig: 13 (lts_kernel.override { 14 structuredExtraConfig = structuredConfig; 15 }).configfile.structuredConfig; 16 17 mandatoryVsOptionalConfig = mkMerge [ 18 { NIXOS_FAKE_USB_DEBUG = yes;} 19 { NIXOS_FAKE_USB_DEBUG = option yes; } 20 ]; 21 22 freeformConfig = mkMerge [ 23 { NIXOS_FAKE_MMC_BLOCK_MINORS = freeform "32"; } # same as default, won't trigger any error 24 { NIXOS_FAKE_MMC_BLOCK_MINORS = freeform "64"; } # will trigger an error but the message is not great: 25 ]; 26 27 mkDefaultWorksConfig = mkMerge [ 28 { "NIXOS_TEST_BOOLEAN" = yes; } 29 { "NIXOS_TEST_BOOLEAN" = lib.mkDefault no; } 30 ]; 31 32 allOptionalRemainOptional = mkMerge [ 33 { NIXOS_FAKE_USB_DEBUG = option yes;} 34 { NIXOS_FAKE_USB_DEBUG = option yes;} 35 ]; 36 37 failures = runTests { 38 testEasy = { 39 expr = (getConfig { NIXOS_FAKE_USB_DEBUG = yes;}).NIXOS_FAKE_USB_DEBUG; 40 expected = { tristate = "y"; optional = false; freeform = null; }; 41 }; 42 43 # mandatory flag should win over optional 44 testMandatoryCheck = { 45 expr = (getConfig mandatoryVsOptionalConfig).NIXOS_FAKE_USB_DEBUG.optional; 46 expected = false; 47 }; 48 49 testYesWinsOverNo = { 50 expr = (getConfig mkDefaultWorksConfig)."NIXOS_TEST_BOOLEAN".tristate; 51 expected = "y"; 52 }; 53 54 testAllOptionalRemainOptional = { 55 expr = (getConfig allOptionalRemainOptional)."NIXOS_FAKE_USB_DEBUG".optional; 56 expected = true; 57 }; 58 59 # check that freeform options are unique 60 # Should trigger 61 # > The option `settings.NIXOS_FAKE_MMC_BLOCK_MINORS.freeform' has conflicting definitions, in `<unknown-file>' and `<unknown-file>' 62 testTreeform = let 63 res = builtins.tryEval ( (getConfig freeformConfig).NIXOS_FAKE_MMC_BLOCK_MINORS.freeform); 64 in { 65 expr = res.success; 66 expected = false; 67 }; 68 69 }; 70in 71 72lib.optional (failures != []) 73 (throw "The following kernel unit tests failed: ${lib.generators.toPretty {} failures}")