2024-05-28 17:10:02 +03:00
|
|
|
# shellcheck shell=bash
|
|
|
|
|
|
|
|
: "${file?must be defined by caller (remote building test case using this)}"
|
|
|
|
|
2023-03-16 22:00:20 +02:00
|
|
|
requireSandboxSupport
|
2024-05-28 17:10:02 +03:00
|
|
|
[[ "${busybox-}" =~ busybox ]] || skipTest "no busybox"
|
2017-05-02 16:35:35 +03:00
|
|
|
|
2023-07-13 22:17:22 +03:00
|
|
|
# Avoid store dir being inside sandbox build-dir
|
2020-06-25 19:26:34 +03:00
|
|
|
unset NIX_STORE_DIR
|
|
|
|
unset NIX_STATE_DIR
|
|
|
|
|
2020-08-12 19:32:36 +03:00
|
|
|
function join_by { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
|
|
|
|
|
2021-06-11 09:37:59 +03:00
|
|
|
EXTRA_SYSTEM_FEATURES=()
|
2021-12-09 17:26:46 +02:00
|
|
|
if [[ -n "${CONTENT_ADDRESSED-}" ]]; then
|
2021-06-11 09:37:59 +03:00
|
|
|
EXTRA_SYSTEM_FEATURES=("ca-derivations")
|
|
|
|
fi
|
|
|
|
|
2020-08-12 19:32:36 +03:00
|
|
|
builders=(
|
|
|
|
# system-features will automatically be added to the outer URL, but not inner
|
|
|
|
# remote-store URL.
|
2024-05-28 17:10:02 +03:00
|
|
|
"ssh://localhost?remote-store=$TEST_ROOT/machine1?system-features=$(join_by "%20" foo "${EXTRA_SYSTEM_FEATURES[@]}") - - 1 1 $(join_by "," foo "${EXTRA_SYSTEM_FEATURES[@]}")"
|
|
|
|
"$TEST_ROOT/machine2 - - 1 1 $(join_by "," bar "${EXTRA_SYSTEM_FEATURES[@]}")"
|
|
|
|
"ssh-ng://localhost?remote-store=$TEST_ROOT/machine3?system-features=$(join_by "%20" baz "${EXTRA_SYSTEM_FEATURES[@]}") - - 1 1 $(join_by "," baz "${EXTRA_SYSTEM_FEATURES[@]}")"
|
2020-08-12 19:32:36 +03:00
|
|
|
)
|
|
|
|
|
2024-05-28 17:10:02 +03:00
|
|
|
chmod -R +w "$TEST_ROOT/machine"* || true
|
|
|
|
rm -rf "$TEST_ROOT/machine"* || true
|
2020-12-09 11:37:39 +02:00
|
|
|
|
2020-06-25 19:26:34 +03:00
|
|
|
# Note: ssh://localhost bypasses ssh, directly invoking nix-store as a
|
|
|
|
# child process. This allows us to test LegacySSHStore::buildDerivation().
|
2020-08-12 19:32:36 +03:00
|
|
|
# ssh-ng://... likewise allows us to test RemoteStore::buildDerivation().
|
2024-05-28 17:10:02 +03:00
|
|
|
nix build -L -v -f "$file" -o "$TEST_ROOT/result" --max-jobs 0 \
|
|
|
|
--arg busybox "$busybox" \
|
|
|
|
--store "$TEST_ROOT/machine0" \
|
2020-08-12 19:32:36 +03:00
|
|
|
--builders "$(join_by '; ' "${builders[@]}")"
|
2017-05-02 16:35:35 +03:00
|
|
|
|
2024-05-28 17:10:02 +03:00
|
|
|
outPath=$(readlink -f "$TEST_ROOT/result")
|
2017-05-02 16:35:35 +03:00
|
|
|
|
2024-05-28 17:10:02 +03:00
|
|
|
grep 'FOO BAR BAZ' "$TEST_ROOT/machine0/$outPath"
|
2020-08-12 16:24:39 +03:00
|
|
|
|
2024-05-28 17:10:02 +03:00
|
|
|
testPrintOutPath=$(nix build -L -v -f "$file" --no-link --print-out-paths --max-jobs 0 \
|
|
|
|
--arg busybox "$busybox" \
|
|
|
|
--store "$TEST_ROOT/machine0" \
|
2022-03-19 20:16:05 +02:00
|
|
|
--builders "$(join_by '; ' "${builders[@]}")"
|
|
|
|
)
|
|
|
|
|
|
|
|
[[ $testPrintOutPath =~ store.*build-remote ]]
|
|
|
|
|
2020-08-12 19:32:36 +03:00
|
|
|
# Ensure that input1 was built on store1 due to the required feature.
|
2024-05-28 17:10:02 +03:00
|
|
|
output=$(nix path-info --store "$TEST_ROOT/machine1" --all)
|
2021-12-09 17:26:46 +02:00
|
|
|
echo "$output" | grepQuiet builder-build-remote-input-1.sh
|
|
|
|
echo "$output" | grepQuietInverse builder-build-remote-input-2.sh
|
|
|
|
echo "$output" | grepQuietInverse builder-build-remote-input-3.sh
|
|
|
|
unset output
|
2017-05-02 16:35:35 +03:00
|
|
|
|
2020-08-12 19:32:36 +03:00
|
|
|
# Ensure that input2 was built on store2 due to the required feature.
|
2024-05-28 17:10:02 +03:00
|
|
|
output=$(nix path-info --store "$TEST_ROOT/machine2" --all)
|
2021-12-09 17:26:46 +02:00
|
|
|
echo "$output" | grepQuietInverse builder-build-remote-input-1.sh
|
|
|
|
echo "$output" | grepQuiet builder-build-remote-input-2.sh
|
|
|
|
echo "$output" | grepQuietInverse builder-build-remote-input-3.sh
|
|
|
|
unset output
|
2020-08-12 16:24:39 +03:00
|
|
|
|
|
|
|
# Ensure that input3 was built on store3 due to the required feature.
|
2024-05-28 17:10:02 +03:00
|
|
|
output=$(nix path-info --store "$TEST_ROOT/machine3" --all)
|
2021-12-09 17:26:46 +02:00
|
|
|
echo "$output" | grepQuietInverse builder-build-remote-input-1.sh
|
|
|
|
echo "$output" | grepQuietInverse builder-build-remote-input-2.sh
|
|
|
|
echo "$output" | grepQuiet builder-build-remote-input-3.sh
|
|
|
|
unset output
|
2021-08-24 00:47:29 +03:00
|
|
|
|
2022-02-20 16:56:22 +02:00
|
|
|
|
2022-03-08 07:02:25 +02:00
|
|
|
for i in input1 input3; do
|
2024-05-28 17:10:02 +03:00
|
|
|
nix log --store "$TEST_ROOT/machine0" --file "$file" --arg busybox "$busybox" "passthru.$i" | grep hi-$i
|
2022-03-08 07:02:25 +02:00
|
|
|
done
|
2022-02-20 16:56:22 +02:00
|
|
|
|
2021-08-24 00:47:29 +03:00
|
|
|
# Behavior of keep-failed
|
|
|
|
out="$(nix-build 2>&1 failing.nix \
|
2022-05-02 10:38:51 +03:00
|
|
|
--no-out-link \
|
2021-08-24 00:47:29 +03:00
|
|
|
--builders "$(join_by '; ' "${builders[@]}")" \
|
|
|
|
--keep-failed \
|
2024-05-28 17:10:02 +03:00
|
|
|
--store "$TEST_ROOT/machine0" \
|
2021-08-24 00:47:29 +03:00
|
|
|
-j0 \
|
2024-05-28 17:10:02 +03:00
|
|
|
--arg busybox "$busybox")" || true
|
2021-08-24 00:47:29 +03:00
|
|
|
|
|
|
|
[[ "$out" =~ .*"note: keeping build directory".* ]]
|
|
|
|
|
|
|
|
build_dir="$(grep "note: keeping build" <<< "$out" | sed -E "s/^(.*)note: keeping build directory '(.*)'(.*)$/\2/")"
|
|
|
|
[[ "foo" = $(<"$build_dir"/bar) ]]
|