1 import ../make-test-python.nix (
10 wg-snakeoil-keys = import ./snakeoil-keys.nix;
13 name = "wireguard-dynamic-refresh";
14 meta = with lib.maintainers; {
15 maintainers = [ majiir ];
20 virtualisation.vlans = [
24 boot = lib.mkIf (kernelPackages != null) { inherit kernelPackages; };
25 networking.firewall.allowedUDPPorts = [ 23542 ];
26 networking.useDHCP = false;
27 networking.wireguard.useNetworkd = useNetworkd;
28 networking.wireguard.interfaces.wg0 = {
29 ips = [ "10.23.42.1/32" ];
32 # !!! Don't do this with real keys. The /nix store is world-readable!
33 privateKeyFile = toString (pkgs.writeText "privateKey" wg-snakeoil-keys.peer0.privateKey);
35 peers = lib.singleton {
36 allowedIPs = [ "10.23.42.2/32" ];
38 inherit (wg-snakeoil-keys.peer1) publicKey;
46 virtualisation.vlans = [
50 boot = lib.mkIf (kernelPackages != null) { inherit kernelPackages; };
51 networking.useDHCP = false;
52 networking.wireguard.useNetworkd = useNetworkd;
53 networking.wireguard.interfaces.wg0 = {
54 ips = [ "10.23.42.2/32" ];
56 # !!! Don't do this with real keys. The /nix store is world-readable!
57 privateKeyFile = toString (pkgs.writeText "privateKey" wg-snakeoil-keys.peer1.privateKey);
59 dynamicEndpointRefreshSeconds = 2;
61 peers = lib.singleton {
66 endpoint = "server:23542";
68 inherit (wg-snakeoil-keys.peer0) publicKey;
72 specialisation.update-hosts.configuration = {
73 networking.extraHosts =
75 testCfg = nodes.server.virtualisation.test;
77 lib.mkForce "192.168.2.${toString testCfg.nodeNumber} ${testCfg.nodeName}";
87 server.systemctl("start network-online.target")
88 server.wait_for_unit("network-online.target")
90 client.systemctl("start network-online.target")
91 client.wait_for_unit("network-online.target")
93 client.succeed("ping -n -w 1 -c 1 10.23.42.1")
95 client.succeed("ip link set down eth1")
97 client.fail("ping -n -w 1 -c 1 10.23.42.1")
99 with client.nested("update hosts file"):
100 client.succeed("${nodes.client.system.build.toplevel}/specialisation/update-hosts/bin/switch-to-configuration test")
102 client.succeed("sleep 5 && ping -n -w 1 -c 1 10.23.42.1")