Skip to content

Commit

Permalink
feat: add nixostests block type
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Feb 17, 2024
1 parent b548f1e commit d54ba55
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/local/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions src/std/fwlib/blockTypes/nixostests.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
root,
super,
}:
/*
Use the NixosTests Blocktype in order to instrucement nixos
vm-based test inside your reporisory.
Available actions:
- run
- run-vm
- audit-script
- run-vm-+
*/
let
inherit (root) mkCommand actions;
inherit (super) addSelectorFunctor;
in
name: {
__functor = addSelectorFunctor;
inherit name;
type = "nixostests";
actions = {
currentSystem,
fragment,
fragmentRelPath,
target,
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
'' {})
];
}
6 changes: 3 additions & 3 deletions src/tests/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d54ba55

Please sign in to comment.