fix: pre-build-hook did not run when useChroot == false
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
This commit is contained in:
@@ -663,7 +663,17 @@ try {
|
||||
if (needsHashRewrite() && pathExists(homeDir))
|
||||
throw Error("home directory '%1%' exists; please remove it to assure purity of builds without sandboxing", homeDir);
|
||||
|
||||
if (useChroot && settings.preBuildHook != "" && dynamic_cast<Derivation *>(drv.get())) {
|
||||
// Note that the derivation may or may not exist when running the
|
||||
// pre-build-hook. In the past this was *supposed* to not run the
|
||||
// hook in such cases, but at some intermediate point (since this->drv
|
||||
// became always an instance of Derivation rather than BasicDerivation), it
|
||||
// started being run in all cases on systems using the sandbox.
|
||||
// https://git.lix.systems/lix-project/lix/commit/7f5b750b401e98e9e2a346552aba5bd2e0a9203f
|
||||
//
|
||||
// As such, we just run it every time. It might be reasonable (and more
|
||||
// helpful behaviour for users) in the future to write out the derivation
|
||||
// to disk if pre-build-hook is in use.
|
||||
if (settings.preBuildHook != "") {
|
||||
printMsg(lvlChatty, "executing pre-build hook '%1%'", settings.preBuildHook);
|
||||
auto drvPathPretty = worker.store.printStorePath(drvPath);
|
||||
auto args = useChroot ? Strings({ drvPathPretty, chrootRootDir}) :
|
||||
|
||||
@@ -9,6 +9,8 @@ settings for this system. This is used for settings that can't be
|
||||
captured by the derivation model itself and are too variable between
|
||||
different versions of the same system to be hard-coded into nix.
|
||||
|
||||
At the time of running the hook, the derivation may or may not exist on disk (and, e.g. won't exist in the case of many remote builds).
|
||||
|
||||
The hook is passed the derivation path and, if sandboxes are
|
||||
enabled, the sandbox directory. It can then modify the sandbox and
|
||||
send a series of commands to modify various settings to stdout. The
|
||||
|
||||
@@ -163,6 +163,7 @@ functional_tests_scripts = [
|
||||
'compression-levels.sh',
|
||||
'nix-copy-ssh.sh',
|
||||
'nix-copy-ssh-ng.sh',
|
||||
'pre-hook.sh',
|
||||
'post-hook.sh',
|
||||
'function-trace.sh',
|
||||
'flakes/config.sh',
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
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)" ]]
|
||||
Reference in New Issue
Block a user