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