2022-01-23 02:50:53 +01:00
|
|
|
{ pkgs ? import ../nixpkgs.nix
|
|
|
|
, evaluator ? "chunked"
|
|
|
|
}:
|
2021-12-08 08:13:31 +01:00
|
|
|
|
2021-12-05 10:14:12 +01:00
|
|
|
let
|
2021-12-08 08:13:31 +01:00
|
|
|
tools = pkgs.callPackage ../tools.nix {
|
2021-12-05 10:14:12 +01:00
|
|
|
targets = [ "alpha" ];
|
|
|
|
};
|
2022-12-01 09:57:56 +01:00
|
|
|
in tools.runTest {
|
2022-01-23 02:50:53 +01:00
|
|
|
name = "colmena-flakes-${evaluator}";
|
2021-12-05 10:14:12 +01:00
|
|
|
|
2022-12-01 09:57:56 +01:00
|
|
|
colmena.test = {
|
|
|
|
bundle = ./.;
|
2021-12-05 10:14:12 +01:00
|
|
|
|
2022-12-01 09:57:56 +01:00
|
|
|
testScript = ''
|
|
|
|
import re
|
2021-12-05 10:14:12 +01:00
|
|
|
|
2022-12-01 09:57:56 +01:00
|
|
|
deployer.succeed("sed -i 's @nixpkgs@ path:${pkgs._inputs.nixpkgs.outPath}?narHash=${pkgs._inputs.nixpkgs.narHash} g' /tmp/bundle/flake.nix")
|
2022-02-05 05:58:17 +01:00
|
|
|
|
2022-12-01 09:57:56 +01:00
|
|
|
with subtest("Lock flake dependencies"):
|
|
|
|
deployer.succeed("cd /tmp/bundle && nix --extra-experimental-features \"nix-command flakes\" flake lock")
|
2021-12-05 10:14:12 +01:00
|
|
|
|
2022-12-01 09:57:56 +01:00
|
|
|
with subtest("Deploy with a plain flake without git"):
|
|
|
|
deployer.succeed("cd /tmp/bundle && ${tools.colmenaExec} apply --on @target --evaluator ${evaluator}")
|
|
|
|
alpha.succeed("grep FIRST /etc/deployment")
|
2021-12-05 10:14:12 +01:00
|
|
|
|
2022-12-01 09:57:56 +01:00
|
|
|
with subtest("Deploy with a git flake"):
|
|
|
|
deployer.succeed("sed -i s/FIRST/SECOND/g /tmp/bundle/probe.nix")
|
2021-12-05 10:14:12 +01:00
|
|
|
|
2022-12-01 09:57:56 +01:00
|
|
|
# don't put probe.nix in source control - should fail
|
|
|
|
deployer.succeed("cd /tmp/bundle && git init && git add flake.nix flake.lock hive.nix tools.nix")
|
|
|
|
logs = deployer.fail("cd /tmp/bundle && run-copy-stderr ${tools.colmenaExec} apply --on @target --evaluator ${evaluator}")
|
|
|
|
assert re.search(r"probe.nix.*No such file or directory", logs)
|
2021-12-05 10:14:12 +01:00
|
|
|
|
2022-12-01 09:57:56 +01:00
|
|
|
# now it should succeed
|
|
|
|
deployer.succeed("cd /tmp/bundle && git add probe.nix")
|
|
|
|
deployer.succeed("cd /tmp/bundle && ${tools.colmenaExec} apply --on @target --evaluator ${evaluator}")
|
|
|
|
alpha.succeed("grep SECOND /etc/deployment")
|
2022-08-17 09:09:43 +02:00
|
|
|
|
2022-12-01 09:57:56 +01:00
|
|
|
with subtest("Check that impure expressions are forbidden"):
|
|
|
|
deployer.succeed("sed -i 's|SECOND|''${builtins.readFile /etc/hostname}|g' /tmp/bundle/probe.nix")
|
|
|
|
logs = deployer.fail("cd /tmp/bundle && run-copy-stderr ${tools.colmenaExec} apply --on @target --evaluator ${evaluator}")
|
|
|
|
assert re.search(r"access to absolute path.*forbidden in pure eval mode", logs)
|
2022-08-17 09:09:43 +02:00
|
|
|
|
2022-12-01 09:57:56 +01:00
|
|
|
with subtest("Check that impure expressions can be allowed with --impure"):
|
|
|
|
deployer.succeed("cd /tmp/bundle && ${tools.colmenaExec} apply --on @target --evaluator ${evaluator} --impure")
|
|
|
|
alpha.succeed("grep deployer /etc/deployment")
|
|
|
|
'';
|
|
|
|
};
|
2021-12-05 10:14:12 +01:00
|
|
|
}
|