aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-13 21:28:11 +0100
committertv <tv@krebsco.de>2026-11-13 21:28:11 +0100
commitd36d2e631e4baceed0a8c0c00859ebb2ab8cb82f (patch)
tree98227d0091b8b23c0c69dcc3e5a770a0da291a37 /tests
parentbcffc9b0a00f3c49db71fe61e8185b9b8e281e55 (diff)
populate: drop the shell implementation
Populate is the program in Rust only. pkgs.populate checks its arguments, and returns a script running the program with them as JSON. The arguments it took for the shell implementation, dash, jq, and implementation, stay accepted and unused, so overrides setting them keep working. Copying flakes to remote targets using sudo gets refused during evaluation, as before, by checks.nix, and by the program for specs from elsewhere. The jq test goes with the jq programs; the program's unit tests cover their equivalents.
Diffstat (limited to 'tests')
-rw-r--r--tests/default.nix26
-rwxr-xr-xtests/jq.sh149
-rw-r--r--tests/scenarios.nix18
3 files changed, 10 insertions, 183 deletions
diff --git a/tests/default.nix b/tests/default.nix
index 189e573..97b64e0 100644
--- a/tests/default.nix
+++ b/tests/default.nix
@@ -7,10 +7,8 @@
# -A exhaustive, or one with, e.g., nix-build tests -A exhaustive.flake.
# 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. implementation selects populate's implementation, e.g. nix-build
-# tests --argstr implementation rust -A smoke.
-{ pkgs ? import ../pkgs {}, implementation ? "shell" }:
+# nix-build tests -A smoke.
+{ pkgs ? import ../pkgs {} }:
let
# HEAD of /fixtures/gitsrc, which fixtures.sh creates deterministically,
@@ -26,11 +24,11 @@ let
# The scenarios, with populate using rsync.
scenariosWith = rsync: let
- populate = pkgs.populate.override { inherit implementation rsync; };
+ populate = pkgs.populate.override { inherit rsync; };
in import ./scenarios.nix {
inherit (pkgs) lib;
krops = import ../lib;
- inherit implementation populate;
+ inherit populate;
inherit (pkgs.krops.override { inherit populate; }) writeDeploy;
url = "http://deployer:8000";
gitUrl = "git://deployer/gitsrc.git";
@@ -40,7 +38,6 @@ let
rsyncVersion = rsync.version;
};
scenarios = scenariosWith pkgs.rsync;
- flakeJq = import ../pkgs/populate/flake-jq.nix;
# VM tests of those of the groups of scenarios that are, or aren't,
# exhaustive, named after the groups with prefix in front.
testsOf = exhaustive: prefix: pkgs.lib.mapAttrs
@@ -109,18 +106,3 @@ in
};
})
rsyncs
- // {
- # Lock files in the shapes different versions of Nix write.
- jq = pkgs.runCommand "krops-jq" {
- nativeBuildInputs = [ pkgs.jq pkgs.nix ];
- } ''
- sh ${./jq.sh} ${pkgs.linkFarm "krops-flake-jq" (map
- (name: { name = "${name}.jq"; path = pkgs.writeText "${name}.jq" flakeJq.${name}; })
- [ "selected" "selfIsRemote" "selfLocked" ]
- ++ [{
- name = "metadataSubdir.nix";
- path = pkgs.writeText "metadataSubdir.nix" flakeJq.metadataSubdir;
- }])}
- touch $out
- '';
- }
diff --git a/tests/jq.sh b/tests/jq.sh
deleted file mode 100755
index 3794ce2..0000000
--- a/tests/jq.sh
+++ /dev/null
@@ -1,149 +0,0 @@
-#! /bin/sh
-# Runs populate's jq programs for flakes over lock files in the shapes
-# different versions of Nix write, without VMs.
-#
-# usage: jq.sh DIR
-#
-# DIR contains the programs as selected.jq, selfIsRemote.jq, and
-# selfLocked.jq, and the Nix function for the target as metadataSubdir.nix.
-set -efu
-
-programs=$1
-failed=0
-
-# usage: expect WHAT ACTUAL EXPECTED
-expect() {
- if test "$2" != "$3"; then
- printf 'FAIL: %s\n expected: %s\n got: %s\n' "$1" "$3" "$2" >&2
- failed=1
- fi
-}
-
-# usage: expect_error WHAT ACTUAL MESSAGE
-expect_error() {
- case $2 in
- *"$3"*) ;;
- *)
- printf 'FAIL: %s\n expected an error: %s\n got: %s\n' "$1" "$3" "$2" >&2
- failed=1
- ;;
- esac
-}
-
-# usage: selection METADATA INPUT
-selection() {
- printf '%s\n' "$1" |
- timeout 10 jq -c --argjson input "$2" --from-file "$programs"/selected.jq 2>&1 ||
- :
-}
-
-# A flake with an input dep, which has an input inner following the flake's
-# input inner, and an input sub, a flake in a subdirectory, written as
-# attribute dir or as query parameter dir of the URL.
-metadata() {
- cat <<JSON
-{
- "locked": { "type": "path", "path": "/src/top", "narHash": "sha256-top" },
- "path": "/nix/store/top-source",
- "locks": {
- "root": "root",
- "version": 7,
- "nodes": {
- "root": { "inputs": { "dep": "dep", "inner": "inner", "sub": "sub" } },
- "dep": {
- "inputs": { "inner": [ "inner" ] },
- "locked": { "type": "tarball", "url": "http://x/dep.tar.gz", "narHash": "sha256-dep" }
- },
- "inner": {
- "locked": { "type": "tarball", "url": "http://x/inner.tar.gz", "narHash": "sha256-inner" }
- },
- "sub": {
- "locked": $1,
- "original": $2
- }
- }
- }
-}
-JSON
-}
-attribute=$(metadata \
- '{ "type": "tarball", "url": "http://x/mono.tar.gz", "dir": "sub", "narHash": "sha256-mono" }' \
- '{ "type": "tarball", "url": "http://x/mono.tar.gz", "dir": "sub" }')
-url=$(metadata \
- '{ "type": "tarball", "url": "http://x/mono.tar.gz?dir=sub", "narHash": "sha256-mono" }' \
- '{ "type": "tarball", "url": "http://x/mono.tar.gz?dir=sub" }')
-
-mono='{"self":false,"locked":{"type":"tarball","url":"http://x/mono.tar.gz","narHash":"sha256-mono"},"subdir":"sub"}'
-expect "subdirectory as attribute" "$(selection "$attribute" '["sub"]')" "$mono"
-expect "subdirectory in the URL" "$(selection "$url" '["sub"]')" "$mono"
-expect "the flake itself" "$(selection "$attribute" '[]')" \
- '{"self":true,"locked":null,"subdir":""}'
-expect "name through follows" "$(selection "$attribute" '["dep","inner"]')" \
- '{"self":false,"locked":{"type":"tarball","url":"http://x/inner.tar.gz","narHash":"sha256-inner"},"subdir":""}'
-expect_error "missing input" "$(selection "$attribute" '["nope"]')" "no input nope"
-
-# An empty follows path removes an input.
-removed=$(printf '%s\n' "$attribute" | jq -c '.locks.nodes.dep.inputs.inner = []')
-expect_error "removed input" "$(selection "$removed" '["dep","inner"]')" "no input inner"
-
-# Inputs following each other.
-cyclic=$(printf '%s\n' "$attribute" | jq -c '
- .locks.nodes.dep.inputs.inner = ["inner", "x"]
- | .locks.nodes.inner.inputs = { x: ["dep", "inner"] }
-')
-expect_error "cyclic follows" "$(selection "$cyclic" '["dep","inner"]')" "follows nest too deep"
-
-# An input given by a path relative to the flake, which is in subdirectory
-# sub itself.
-relative=$(printf '%s\n' "$attribute" | jq -c '
- .locked.dir = "sub"
- | .locks.nodes.root.inputs.lib = "lib"
- | .locks.nodes.lib = { locked: { type: "path", path: "./lib" }, parent: [] }
-')
-expect "relative path" "$(selection "$relative" '["lib"]')" \
- '{"self":true,"locked":null,"subdir":"sub/lib"}'
-
-# usage: remote LOCKED
-remote() {
- printf '{ "locked": %s }\n' "$1" |
- jq --from-file "$programs"/selfIsRemote.jq
-}
-expect "path" "$(remote '{ "type": "path", "path": "/src" }')" false
-expect "local Git" "$(remote '{ "type": "git", "url": "file:///src" }')" false
-expect "remote Git" "$(remote '{ "type": "git", "url": "https://x/y" }')" true
-expect "GitHub" "$(remote '{ "type": "github", "owner": "o", "repo": "r" }')" true
-
-expect "locked reference of the flake itself" "$(
- printf '%s\n' '{ "locked": { "__final": true, "type": "tarball", "url": "http://x/mono.tar.gz?dir=sub", "narHash": "sha256-mono" } }' |
- jq -c --argjson selected '{"self":true,"locked":null,"subdir":"sub"}' \
- --from-file "$programs"/selfLocked.jq
-)" "$mono"
-
-# The Nix function finding the subdirectory on the target, which may lack
-# jq.
-# usage: metadata_subdir METADATA
-metadata_subdir() {
- METADATA=$1 nix-instantiate --eval --strict --json --store dummy:// --expr "
- (import $programs/metadataSubdir.nix)
- (builtins.fromJSON (builtins.getEnv \"METADATA\"))
- " 2>&1 || :
-}
-export HOME=${TMPDIR:-/tmp}
-export NIX_STATE_DIR=$HOME/nix-state
-expect "subdirectory as attribute, on the target" "$(metadata_subdir '{
- "locked": { "type": "tarball", "url": "http://x/mono.tar.gz", "dir": "sub" },
- "original": { "type": "tarball", "url": "http://x/mono.tar.gz", "dir": "sub" }
-}')" '"sub"'
-expect "subdirectory in the URL, on the target" "$(metadata_subdir '{
- "locked": { "type": "tarball", "url": "http://x/mono.tar.gz?dir=sub&narHash=sha256-mono" },
- "original": { "type": "tarball", "url": "http://x/mono.tar.gz?dir=sub" }
-}')" '"sub"'
-expect "subdirectory in the original reference only, on the target" "$(metadata_subdir '{
- "locked": { "type": "tarball", "url": "http://x/mono.tar.gz" },
- "original": { "type": "tarball", "url": "http://x/mono.tar.gz?rev=1&dir=sub" }
-}')" '"sub"'
-expect "no subdirectory, on the target" "$(metadata_subdir '{
- "locked": { "type": "path", "path": "/src/top" }
-}')" '""'
-
-exit "$failed"
diff --git a/tests/scenarios.nix b/tests/scenarios.nix
index cda72bd..14a2c91 100644
--- a/tests/scenarios.nix
+++ b/tests/scenarios.nix
@@ -28,8 +28,6 @@
gitFirst,
# Version of rsync on the deploying machine.
rsyncVersion,
- # The implementation of populate, "shell" or "rust".
- implementation,
}:
let
@@ -230,16 +228,12 @@ 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";
- };
+ # A phase copying flakes to a target using sudo, which isn't supported,
+ # and gets refused during evaluation.
+ refuseCopyingWithSudo = {
+ expect = "eval-error";
+ control = withFetchOnTarget;
+ };
in