Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/macos nixostests actions #370

Merged
merged 2 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
'' {})
];
}
42 changes: 37 additions & 5 deletions tests/bt-blocktypes/expr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
std,
nixpkgs,
}: let
inherit (builtins) mapAttrs concatStringsSep seq removeAttrs;
inherit (nixpkgs.lib) splitString drop pipe;
inherit (builtins) mapAttrs concatStringsSep seq removeAttrs derivation;
inherit (nixpkgs.lib) splitString drop pipe optionalAttrs;
inherit (nixpkgs.stdenv) isLinux;
inherit (std) dmerge;
trimProvisoPath = a:
if a ? proviso
then a // {proviso = concatStringsSep "/" (drop 4 (splitString "/" a.proviso));}
Expand Down Expand Up @@ -69,6 +71,29 @@
}
.${n}
or (f n)) ["__functor"];
# fake snapshot compliance across systems
FakeActionsForOtherSystems = let
fakeDrv = name:
derivation {
inherit name;
system = "fake";
builder = "/bin/sh";
};
in
optionalAttrs (!isLinux) {
nixostests = dmerge.append [
{
command = fakeDrv "iptables+";
description = "setup nat redirect 80->8080 & 443->4433";
name = "iptables+";
}
{
command = fakeDrv "iptables-";
description = "remove nat redirect 80->8080 & 443->4433";
name = "iptables-";
}
];
};
in
mapAttrs (
n: f: let
Expand All @@ -78,14 +103,21 @@ in
then
bt
// {
actions =
pipe (bt.actions {
actions = let
actions' = bt.actions {
inherit inputs;
currentSystem = inputs.nixpkgs.system;
fragment = "f.r.a.g.m.e.n.t";
fragmentRelPath = "x86/f/r/a/g/m/e/n/t";
target = TargetsExtraData.${n} or {};
}) [
};
r =
(
dmerge {${n} = actions';} FakeActionsForOtherSystems
)
.${n};
in
pipe r [
(map trimProvisoPath)
(map evalCommand)
];
Expand Down
Loading