aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-13 16:23:34 +0100
committertv <tv@krebsco.de>2026-11-13 16:23:34 +0100
commit50a2b8f9628bacdc8f13848e98b909e7be44c640 (patch)
tree3ecc002e39c7cd7147f4a49d7c3e874fa4b344dd /tests
parent4afd7d2793e85f260a2a3c20a423f0d1a4844ea7 (diff)
populate: add a Rust implementation, selectable for the tests
pkgs.populate takes implementation: "shell", the default, generates a script from populate's arguments, and "rust" passes them as JSON to the program in pkgs/populate, built from the crate there by program.nix. The program checks the spec as checks.nix does during evaluation, with the same messages, and reports that delivering sources isn't implemented yet. rustProgram replaces the program, e.g. with one built some other way. checks.nix holds the checks of populate's arguments during evaluation. Both implementations check the names of sources and the target path with it, and the Rust one's wrapper also checks drawing inputs, which the shell implementation checks where it draws them. nix-build tests --argstr implementation rust runs the scenarios with the Rust implementation. They expect it to refuse copying flakes to targets using sudo when it runs, not during evaluation, because only then it decides whether the target is local.
Diffstat (limited to 'tests')
-rw-r--r--tests/default.nix13
-rw-r--r--tests/scenarios.nix23
2 files changed, 23 insertions, 13 deletions
diff --git a/tests/default.nix b/tests/default.nix
index f7ffa71..189e573 100644
--- a/tests/default.nix
+++ b/tests/default.nix
@@ -8,8 +8,9 @@
# The smoke test runs a few scenarios covering each source type and each kind
# of target in a single VM test, for checking changes quickly; build it with
# nix-build tests -A smoke. jq runs populate's jq programs for flakes without
-# VMs.
-{ pkgs ? import ../pkgs {} }:
+# VMs. implementation selects populate's implementation, e.g. nix-build
+# tests --argstr implementation rust -A smoke.
+{ pkgs ? import ../pkgs {}, implementation ? "shell" }:
let
# HEAD of /fixtures/gitsrc, which fixtures.sh creates deterministically,
@@ -24,11 +25,13 @@ let
(pkgs.callPackage ./rsync.nix {});
# The scenarios, with populate using rsync.
- scenariosWith = rsync: import ./scenarios.nix {
+ scenariosWith = rsync: let
+ populate = pkgs.populate.override { inherit implementation rsync; };
+ in import ./scenarios.nix {
inherit (pkgs) lib;
krops = import ../lib;
- populate = pkgs.populate.override { inherit rsync; };
- inherit (pkgs.krops) writeDeploy;
+ inherit implementation populate;
+ inherit (pkgs.krops.override { inherit populate; }) writeDeploy;
url = "http://deployer:8000";
gitUrl = "git://deployer/gitsrc.git";
remoteHost = "target";
diff --git a/tests/scenarios.nix b/tests/scenarios.nix
index 2fc1bd7..cda72bd 100644
--- a/tests/scenarios.nix
+++ b/tests/scenarios.nix
@@ -28,6 +28,8 @@
gitFirst,
# Version of rsync on the deploying machine.
rsyncVersion,
+ # The implementation of populate, "shell" or "rust".
+ implementation,
}:
let
@@ -228,6 +230,17 @@ let
then options // { fetchOnTarget = true; }
else options));
+ # A phase copying flakes to a target using sudo, which isn't supported:
+ # the shell implementation refuses during evaluation, the Rust one when it
+ # runs, because only then it decides whether the target is local.
+ refuseCopyingWithSudo =
+ if implementation == "shell" then {
+ expect = "eval-error";
+ control = withFetchOnTarget;
+ } else {
+ expect.fail = "copying flakes to targets with sudo is not supported";
+ };
+
in
# The remote target must not count as local wherever this gets evaluated.
@@ -431,10 +444,7 @@ assert !(krops.isLocalTarget (targets.remote "/"));
inherit (flags) fetchOnTarget materialize;
} // drawInputs flags.inputs { dep.follows = "alt"; };
} // optionalAttrs (flags.inputs != "none") alt;
- } // (if copyingWithSudo flags ctx then {
- expect = "eval-error";
- control = withFetchOnTarget;
- } else {
+ } // (if copyingWithSudo flags ctx then refuseCopyingWithSudo else {
check = if flags.kind == "subdir" then checkFlake {
attr = "who"; expected = "sub"; subdir = true;
materialized = flags.materialize;
@@ -466,10 +476,7 @@ assert !(krops.isLocalTarget (targets.remote "/"));
inherit (flags) fetchOnTarget materialize;
} // drawInputs inputs { inner.follows = "alt"; };
} // optionalAttrs (inputs != "none") alt;
- } // (if copyingWithSudo flags ctx then {
- expect = "eval-error";
- control = withFetchOnTarget;
- } else {
+ } // (if copyingWithSudo flags ctx then refuseCopyingWithSudo else {
check = {
dep = checkFlake {
attr = "greeting";