diff options
author | Naïm Favier <n@monade.li> | 2022-12-26 12:26:20 +0100 |
---|---|---|
committer | Naïm Favier <n@monade.li> | 2022-12-26 12:46:45 +0100 |
commit | c4bd20a68602c22ef8a872c7c14ad69c13d4f503 (patch) | |
tree | 1d8b72861aef6926252d8d469010de432b879f90 | |
parent | dc1e00bd8bcf7040573a3a6721fd264d900d13d4 (diff) | |
download | nixpkgs-c4bd20a68602c22ef8a872c7c14ad69c13d4f503.tar nixpkgs-c4bd20a68602c22ef8a872c7c14ad69c13d4f503.tar.gz nixpkgs-c4bd20a68602c22ef8a872c7c14ad69c13d4f503.tar.bz2 nixpkgs-c4bd20a68602c22ef8a872c7c14ad69c13d4f503.tar.lz nixpkgs-c4bd20a68602c22ef8a872c7c14ad69c13d4f503.tar.xz nixpkgs-c4bd20a68602c22ef8a872c7c14ad69c13d4f503.tar.zst nixpkgs-c4bd20a68602c22ef8a872c7c14ad69c13d4f503.zip |
nixos/wg-quick: add nftables test
-rw-r--r-- | nixos/tests/wireguard/basic.nix | 3 | ||||
-rw-r--r-- | nixos/tests/wireguard/default.nix | 3 | ||||
-rw-r--r-- | nixos/tests/wireguard/generated.nix | 3 | ||||
-rw-r--r-- | nixos/tests/wireguard/namespaces.nix | 4 | ||||
-rw-r--r-- | nixos/tests/wireguard/wg-quick.nix | 74 |
5 files changed, 46 insertions, 41 deletions
diff --git a/nixos/tests/wireguard/basic.nix b/nixos/tests/wireguard/basic.nix index 36ab226cde0..96b0a681c36 100644 --- a/nixos/tests/wireguard/basic.nix +++ b/nixos/tests/wireguard/basic.nix @@ -1,5 +1,4 @@ -{ kernelPackages ? null }: -import ../make-test-python.nix ({ pkgs, lib, ...} : +import ../make-test-python.nix ({ pkgs, lib, kernelPackages ? null, ...} : let wg-snakeoil-keys = import ./snakeoil-keys.nix; peer = (import ./make-peer.nix) { inherit lib; }; diff --git a/nixos/tests/wireguard/default.nix b/nixos/tests/wireguard/default.nix index dedb321ff2e..c30f1b74770 100644 --- a/nixos/tests/wireguard/default.nix +++ b/nixos/tests/wireguard/default.nix @@ -7,10 +7,11 @@ with pkgs.lib; let - tests = let callTest = p: flip (import p) { inherit system pkgs; }; in { + tests = let callTest = p: args: import p ({ inherit system pkgs; } // args); in { basic = callTest ./basic.nix; namespaces = callTest ./namespaces.nix; wg-quick = callTest ./wg-quick.nix; + wg-quick-nftables = args: callTest ./wg-quick.nix ({ nftables = true; } // args); generated = callTest ./generated.nix; }; in diff --git a/nixos/tests/wireguard/generated.nix b/nixos/tests/wireguard/generated.nix index 84a35d29b45..c58f7a75071 100644 --- a/nixos/tests/wireguard/generated.nix +++ b/nixos/tests/wireguard/generated.nix @@ -1,5 +1,4 @@ -{ kernelPackages ? null }: -import ../make-test-python.nix ({ pkgs, lib, ... } : { +import ../make-test-python.nix ({ pkgs, lib, kernelPackages ? null, ... } : { name = "wireguard-generated"; meta = with pkgs.lib.maintainers; { maintainers = [ ma27 grahamc ]; diff --git a/nixos/tests/wireguard/namespaces.nix b/nixos/tests/wireguard/namespaces.nix index 93dc84a8768..1790c45bb1f 100644 --- a/nixos/tests/wireguard/namespaces.nix +++ b/nixos/tests/wireguard/namespaces.nix @@ -1,5 +1,3 @@ -{ kernelPackages ? null }: - let listenPort = 12345; socketNamespace = "foo"; @@ -15,7 +13,7 @@ let in -import ../make-test-python.nix ({ pkgs, lib, ... } : { +import ../make-test-python.nix ({ pkgs, lib, kernelPackages ? null, ... } : { name = "wireguard-with-namespaces"; meta = with pkgs.lib.maintainers; { maintainers = [ asymmetric ]; diff --git a/nixos/tests/wireguard/wg-quick.nix b/nixos/tests/wireguard/wg-quick.nix index bc2cba91188..ec2b8d7f2d9 100644 --- a/nixos/tests/wireguard/wg-quick.nix +++ b/nixos/tests/wireguard/wg-quick.nix @@ -1,9 +1,13 @@ -{ kernelPackages ? null }: - -import ../make-test-python.nix ({ pkgs, lib, ... }: +import ../make-test-python.nix ({ pkgs, lib, kernelPackages ? null, nftables ? false, ... }: let wg-snakeoil-keys = import ./snakeoil-keys.nix; - peer = (import ./make-peer.nix) { inherit lib; }; + peer = import ./make-peer.nix { inherit lib; }; + commonConfig = { + boot.kernelPackages = lib.mkIf (kernelPackages != null) kernelPackages; + networking.nftables.enable = nftables; + # Make sure iptables doesn't work with nftables enabled + boot.blacklistedKernelModules = lib.mkIf nftables [ "nft_compat" ]; + }; in { name = "wg-quick"; @@ -15,47 +19,51 @@ import ../make-test-python.nix ({ pkgs, lib, ... }: peer0 = peer { ip4 = "192.168.0.1"; ip6 = "fd00::1"; - extraConfig = { - boot = lib.mkIf (kernelPackages != null) { inherit kernelPackages; }; - networking.firewall.allowedUDPPorts = [ 23542 ]; - networking.wg-quick.interfaces.wg0 = { - address = [ "10.23.42.1/32" "fc00::1/128" ]; - listenPort = 23542; + extraConfig = lib.mkMerge [ + commonConfig + { + networking.firewall.allowedUDPPorts = [ 23542 ]; + networking.wg-quick.interfaces.wg0 = { + address = [ "10.23.42.1/32" "fc00::1/128" ]; + listenPort = 23542; - inherit (wg-snakeoil-keys.peer0) privateKey; + inherit (wg-snakeoil-keys.peer0) privateKey; - peers = lib.singleton { - allowedIPs = [ "10.23.42.2/32" "fc00::2/128" ]; + peers = lib.singleton { + allowedIPs = [ "10.23.42.2/32" "fc00::2/128" ]; - inherit (wg-snakeoil-keys.peer1) publicKey; - }; + inherit (wg-snakeoil-keys.peer1) publicKey; + }; - dns = [ "10.23.42.2" "fc00::2" "wg0" ]; - }; - }; + dns = [ "10.23.42.2" "fc00::2" "wg0" ]; + }; + } + ]; }; peer1 = peer { ip4 = "192.168.0.2"; ip6 = "fd00::2"; - extraConfig = { - boot = lib.mkIf (kernelPackages != null) { inherit kernelPackages; }; - networking.useNetworkd = true; - networking.wg-quick.interfaces.wg0 = { - address = [ "10.23.42.2/32" "fc00::2/128" ]; - inherit (wg-snakeoil-keys.peer1) privateKey; + extraConfig = lib.mkMerge [ + commonConfig + { + networking.useNetworkd = true; + networking.wg-quick.interfaces.wg0 = { + address = [ "10.23.42.2/32" "fc00::2/128" ]; + inherit (wg-snakeoil-keys.peer1) privateKey; - peers = lib.singleton { - allowedIPs = [ "0.0.0.0/0" "::/0" ]; - endpoint = "192.168.0.1:23542"; - persistentKeepalive = 25; + peers = lib.singleton { + allowedIPs = [ "0.0.0.0/0" "::/0" ]; + endpoint = "192.168.0.1:23542"; + persistentKeepalive = 25; - inherit (wg-snakeoil-keys.peer0) publicKey; - }; + inherit (wg-snakeoil-keys.peer0) publicKey; + }; - dns = [ "10.23.42.1" "fc00::1" "wg0" ]; - }; - }; + dns = [ "10.23.42.1" "fc00::1" "wg0" ]; + }; + } + ]; }; }; |