Skip to content

Commit

Permalink
fix: nixostest blocktype where iptables is a linux-only tool
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Feb 18, 2024
1 parent e0ee7e8 commit 5b69855
Showing 1 changed file with 49 additions and 44 deletions.
93 changes: 49 additions & 44 deletions src/std/fwlib/blockTypes/nixostests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,48 +28,53 @@ in
inputs,
}: let
pkgs = inputs.nixpkgs.${currentSystem};
in [
(mkCommand currentSystem "run" "run tests in headless vm" [] ''
# ${target.driver}
${target.driver}/bin/nixos-test-driver
'' {})
(mkCommand currentSystem "audit-script" "audit the test script" [pkgs.bat] ''
# ${target.driver}
bat --language py ${target.driver}/test-script
'' {})
(mkCommand currentSystem "run-vm" "run tests interactively in vm" [] ''
# ${target.driverInteractive}
${target.driverInteractive}/bin/nixos-test-driver
'' {})
(mkCommand currentSystem "run-vm+" "run tests with state from last run" [] ''
# ${target.driverInteractive}
${target.driverInteractive}/bin/nixos-test-driver --keep-vm-state
'' {})
(mkCommand currentSystem "iptables+" "setup nat redirect 80->8080 & 443->4433" [pkgs.iptables] ''
sudo iptables \
--table nat \
--insert OUTPUT \
--proto tcp \
--destination 127.0.0.1 \
--dport 443 \
--jump REDIRECT \
--to-ports 4433
sudo iptables \
--table nat \
--insert OUTPUT \
--proto tcp \
--destination 127.0.0.1 \
--dport 80 \
--jump REDIRECT \
--to-ports 8080
'' {})
(mkCommand currentSystem "iptables-" "remove nat redirect 80->8080 & 443->4433" [pkgs.iptables] ''
sudo iptables \
--table nat \
--delete OUTPUT -d 127.0.0.1/32 -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 4433
sudo iptables \
--table nat \
--delete OUTPUT -d 127.0.0.1/32 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
'' {})
];
inherit (pkgs) lib;
inherit (pkgs.stdenv) isLinux;
in
[
(mkCommand currentSystem "run" "run tests in headless vm" [] ''
# ${target.driver}
${target.driver}/bin/nixos-test-driver
'' {})
(mkCommand currentSystem "audit-script" "audit the test script" [pkgs.bat] ''
# ${target.driver}
bat --language py ${target.driver}/test-script
'' {})
(mkCommand currentSystem "run-vm" "run tests interactively in vm" [] ''
# ${target.driverInteractive}
${target.driverInteractive}/bin/nixos-test-driver
'' {})
(mkCommand currentSystem "run-vm+" "run tests with state from last run" [] ''
# ${target.driverInteractive}
${target.driverInteractive}/bin/nixos-test-driver --keep-vm-state
'' {})
]
++ lib.optionals isLinux [
(mkCommand currentSystem "iptables+" "setup nat redirect 80->8080 & 443->4433" [pkgs.iptables] ''
sudo iptables \
--table nat \
--insert OUTPUT \
--proto tcp \
--destination 127.0.0.1 \
--dport 443 \
--jump REDIRECT \
--to-ports 4433
sudo iptables \
--table nat \
--insert OUTPUT \
--proto tcp \
--destination 127.0.0.1 \
--dport 80 \
--jump REDIRECT \
--to-ports 8080
'' {})
(mkCommand currentSystem "iptables-" "remove nat redirect 80->8080 & 443->4433" [pkgs.iptables] ''
sudo iptables \
--table nat \
--delete OUTPUT -d 127.0.0.1/32 -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 4433
sudo iptables \
--table nat \
--delete OUTPUT -d 127.0.0.1/32 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
'' {})
];
}

0 comments on commit 5b69855

Please sign in to comment.