It turns out there is actually some history here.
Eight years ago, in 7f5b750b40, the
pre-build-hook condition got changed to check that useChroot is true
(which we will put down as "eelco making a mistake" because it makes no
sense) and that this->drv was a Derivation (as opposed to a
BasicDerivation as would be the case if the derivation was not present
on disk). The intent of this change was that pre-build-hook would not
run when the derivation doesn't exist, so that some hydras would not
explode.
However, this broke later when both cases became Derivation such that
AFAICT it will always run it if useChroot is true, which is absolutely
not the intended behaviour, but it is a reasonable interpretation as
well, just inconvenient for certain pre-build-hook usages.
So, I think the safest and most compatible behaviour is to run the
pre-build-hook but not guarantee that the derivation actually exists on
disk, since it already didn't run in many cases. Maybe the more correct
way is to actually write out the derivation if we are running a
pre-build-hook, but post-build-hook has exactly the same situation and
it's expected, so idk.
Fixes: https://git.lix.systems/lix-project/lix/issues/674
Change-Id: I75b828ae2a07ab373f44083507eb243459bd081d
32 lines
854 B
Bash
32 lines
854 B
Bash
source common.sh
|
|
|
|
clearStore
|
|
|
|
rm -f "$TEST_ROOT/result"
|
|
|
|
cat > "$TEST_ROOT/pre-hook.sh" <<-'EOF'
|
|
#!/bin/sh
|
|
|
|
# log the drvs that have been pre-hooked
|
|
echo "$1" >> "$(dirname "$0")"/drvs.txt
|
|
# sandbox: we have a sandbox path as second arg
|
|
if [[ $# == 2 ]]; then
|
|
# FIXME: verify this is actually present inside the derivation builder
|
|
# where sandbox is available.
|
|
echo extra-sandbox-paths
|
|
echo /foo=/bin/sh
|
|
echo
|
|
else
|
|
echo
|
|
fi
|
|
EOF
|
|
|
|
chmod +x "$TEST_ROOT/pre-hook.sh"
|
|
drvPath="$(nix eval --raw -f dependencies.nix drvPath)"
|
|
nix-store -r "$drvPath" --pre-build-hook "$TEST_ROOT/pre-hook.sh"
|
|
|
|
# We expect that the pre build hook got called on all the derivations in the closure we built
|
|
numDrvs="$(nix-store --query --requisites "$drvPath" | grep -c '\.drv$')"
|
|
[[ "$numDrvs" -gt 1 ]]
|
|
[[ "$numDrvs" == "$(< "$TEST_ROOT/drvs.txt" wc -l)" ]]
|