Skip to content

Commit c3cb263

Browse files
committed
Simplify nixosTest networking and add sshBackdoor for interactive debugging
- Remove unnecessary iptables masquerading wrapper (SLiRP provides NAT automatically) - Simplify cluster-module.nix to just disable firewall (DHCP + DNS work out of box) - Enable sshBackdoor in integration.nix for vsock SSH access - Use nixosTests.containerd.driverInteractive directly (no wrapper needed) - Background test with upterm for parallel interactive debugging via 'ssh -F ssh_config vsock/3'
1 parent d022674 commit c3cb263

4 files changed

Lines changed: 5 additions & 65 deletions

File tree

.github/workflows/test-nixos.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
6868
- name: Start nixos test (background)
6969
run: |
70-
nix run --file . nixosNatTest.containerd.driverInteractive --option sandbox false -- --no-interactive > /tmp/test.log 2>&1 &
70+
nix run --file . nixosTests.containerd.driverInteractive --option sandbox false -- --no-interactive > /tmp/test.log 2>&1 &
7171
echo $! > /tmp/test.pid
7272
echo "Test running in background (PID: $(cat /tmp/test.pid))"
7373
sleep 5

default.nix

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -172,65 +172,6 @@ rec {
172172
};
173173
};
174174

175-
# Wrapper that adds iptables masquerading setup for tests requiring external network access
176-
nixosNatTest = lib.mapAttrs (
177-
name: test:
178-
let
179-
iptablesSetup = pkgs.writeShellScript "iptables-nat-setup" ''
180-
set -euo pipefail
181-
182-
# Get the primary network interface (excluding loopback)
183-
HOST_IFACE=$(ip route | grep "^default" | awk '{print $5}' | head -1)
184-
if [ -z "$HOST_IFACE" ]; then
185-
echo "ERROR: Could not determine primary network interface" >&2
186-
exit 1
187-
fi
188-
189-
echo "Setting up iptables masquerading on $HOST_IFACE..."
190-
191-
# Enable IP forwarding
192-
sudo sysctl -w net.ipv4.ip_forward=1
193-
194-
# Add masquerade rule for outbound traffic
195-
sudo iptables -t nat -A POSTROUTING -o "$HOST_IFACE" -j MASQUERADE || true
196-
197-
# Allow forwarding of established connections
198-
sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT || true
199-
200-
# Allow forward traffic from vde/qemu interfaces
201-
sudo iptables -A FORWARD -i vnet+ -o "$HOST_IFACE" -j ACCEPT || true
202-
'';
203-
204-
iptablesCleanup = pkgs.writeShellScript "iptables-nat-cleanup" ''
205-
set -euo pipefail
206-
207-
HOST_IFACE=$(ip route | grep "^default" | awk '{print $5}' | head -1)
208-
if [ -z "$HOST_IFACE" ]; then
209-
exit 0
210-
fi
211-
212-
echo "Cleaning up iptables rules..."
213-
sudo iptables -t nat -D POSTROUTING -o "$HOST_IFACE" -j MASQUERADE || true
214-
sudo iptables -D FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT || true
215-
sudo iptables -D FORWARD -i vnet+ -o "$HOST_IFACE" -j ACCEPT || true
216-
'';
217-
218-
wrappedDriver = pkgs.writeShellScriptBin "nixos-test-driver" ''
219-
set -euo pipefail
220-
221-
# Setup and cleanup traps
222-
trap "${iptablesCleanup}" EXIT
223-
224-
# Setup iptables
225-
${iptablesSetup}
226-
227-
# Run the actual test driver
228-
exec ${test.driverInteractive}/bin/nixos-test-driver "$@"
229-
'';
230-
in
231-
test // { driverInteractive = wrappedDriver; }
232-
) nixosTests;
233-
234175
lixImage = pkgs.callPackage ./liximage.nix { };
235176
scratchImage = pkgs.callPackage ./scratchimage.nix { };
236177
}

tests/nixos/cluster-module.nix

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@
161161
];
162162

163163
# Enable external networking for image pulls and nix binary cache access
164-
networking = {
165-
useDHCP = true;
166-
firewall.enable = false;
167-
nameservers = [ "9.9.9.9" ];
168-
};
164+
# SLiRP provides DHCP + DNS automatically
165+
networking.firewall.enable = false;
169166
}

tests/nixos/integration.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
pkgs.testers.nixosTest {
2929
name = "nixkube-containerd";
3030

31+
sshBackdoor.enable = true;
32+
3133
nodes.control =
3234
{ config, pkgs, ... }:
3335
{

0 commit comments

Comments
 (0)