3 socketNamespace = "foo";
4 interfaceNamespace = "bar";
6 networking.wireguard.interfaces.wg0 = {
7 listenPort = listenPort;
8 ips = [ "10.10.10.1/24" ];
9 privateKeyFile = "/etc/wireguard/private";
10 generatePrivateKeyFile = true;
16 import ../make-test-python.nix ({ pkgs, lib, kernelPackages ? null, ... } : {
17 name = "wireguard-with-namespaces";
18 meta = with pkgs.lib.maintainers; {
19 maintainers = [ asymmetric ];
23 # interface should be created in the socketNamespace
24 # and not moved from there
25 peer0 = pkgs.lib.attrsets.recursiveUpdate node {
26 boot = lib.mkIf (kernelPackages != null) { inherit kernelPackages; };
27 networking.wireguard.interfaces.wg0 = {
29 ip netns add ${socketNamespace}
31 inherit socketNamespace;
34 # interface should be created in the init namespace
35 # and moved to the interfaceNamespace
36 peer1 = pkgs.lib.attrsets.recursiveUpdate node {
37 boot = lib.mkIf (kernelPackages != null) { inherit kernelPackages; };
38 networking.wireguard.interfaces.wg0 = {
40 ip netns add ${interfaceNamespace}
43 inherit interfaceNamespace;
46 # interface should be created in the socketNamespace
47 # and moved to the interfaceNamespace
48 peer2 = pkgs.lib.attrsets.recursiveUpdate node {
49 boot = lib.mkIf (kernelPackages != null) { inherit kernelPackages; };
50 networking.wireguard.interfaces.wg0 = {
52 ip netns add ${socketNamespace}
53 ip netns add ${interfaceNamespace}
55 inherit socketNamespace interfaceNamespace;
58 # interface should be created in the socketNamespace
59 # and moved to the init namespace
60 peer3 = pkgs.lib.attrsets.recursiveUpdate node {
61 boot = lib.mkIf (kernelPackages != null) { inherit kernelPackages; };
62 networking.wireguard.interfaces.wg0 = {
64 ip netns add ${socketNamespace}
66 inherit socketNamespace;
67 interfaceNamespace = "init";
75 for machine in peer0, peer1, peer2, peer3:
76 machine.wait_for_unit("wireguard-wg0.service")
78 peer0.succeed("ip -n ${socketNamespace} link show wg0")
79 peer1.succeed("ip -n ${interfaceNamespace} link show wg0")
80 peer2.succeed("ip -n ${interfaceNamespace} link show wg0")
81 peer3.succeed("ip link show wg0")