at master 2.5 kB view raw
1{ 2 system ? builtins.currentSystem, 3 config ? { }, 4 pkgs ? import ../.. { inherit system config; }, 5}: 6 7let 8 inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest; 9 testCombinations = pkgs.lib.cartesianProduct { 10 predictable = [ 11 true 12 false 13 ]; 14 withNetworkd = [ 15 true 16 false 17 ]; 18 systemdStage1 = [ 19 true 20 false 21 ]; 22 }; 23in 24pkgs.lib.listToAttrs ( 25 builtins.map ( 26 { 27 predictable, 28 withNetworkd, 29 systemdStage1, 30 }: 31 { 32 name = 33 pkgs.lib.optionalString (!predictable) "un" 34 + "predictable" 35 + pkgs.lib.optionalString withNetworkd "Networkd" 36 + pkgs.lib.optionalString systemdStage1 "SystemdStage1"; 37 value = makeTest { 38 name = 39 pkgs.lib.optionalString (!predictable) "un" 40 + "predictableInterfaceNames" 41 + pkgs.lib.optionalString withNetworkd "-with-networkd" 42 + pkgs.lib.optionalString systemdStage1 "-systemd-stage-1"; 43 meta = { }; 44 45 nodes.machine = 46 { lib, ... }: 47 let 48 script = '' 49 ip link 50 if ${lib.optionalString predictable "!"} ip link show eth0; then 51 echo Success 52 else 53 exit 1 54 fi 55 ''; 56 in 57 { 58 networking.usePredictableInterfaceNames = lib.mkForce predictable; 59 networking.useNetworkd = withNetworkd; 60 networking.dhcpcd.enable = !withNetworkd; 61 networking.useDHCP = !withNetworkd; 62 63 # Check if predictable interface names are working in stage-1 64 boot.initrd.postDeviceCommands = lib.mkIf (!systemdStage1) script; 65 66 boot.initrd.systemd = lib.mkIf systemdStage1 { 67 enable = true; 68 initrdBin = [ pkgs.iproute2 ]; 69 services.systemd-udev-settle.wantedBy = [ "initrd.target" ]; 70 services.check-interfaces = { 71 requiredBy = [ "initrd.target" ]; 72 after = [ "systemd-udev-settle.service" ]; 73 serviceConfig.Type = "oneshot"; 74 path = [ pkgs.iproute2 ]; 75 inherit script; 76 }; 77 }; 78 }; 79 80 testScript = '' 81 print(machine.succeed("ip link")) 82 machine.${if predictable then "fail" else "succeed"}("ip link show eth0") 83 ''; 84 }; 85 } 86 ) testCombinations 87)