Skip to content

Commit

Permalink
Merge pull request #4158 from hercules-ci/issue-3964-substitution-loop
Browse files Browse the repository at this point in the history
Fix substitution loop #3964, #3534
  • Loading branch information
edolstra authored Oct 18, 2020
2 parents 05e6fe6 + bd9eb5c commit 67cc94b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/libstore/build/derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,13 @@ void DerivationGoal::outputsSubstitutionTried()

/* If the substitutes form an incomplete closure, then we should
build the dependencies of this derivation, but after that, we
can still use the substitutes for this derivation itself. */
if (nrIncompleteClosure > 0) retrySubstitution = true;
can still use the substitutes for this derivation itself.
If the nrIncompleteClosure != nrFailed, we have another issue as well.
In particular, it may be the case that the hole in the closure is
an output of the current derivation, which causes a loop if retried.
*/
if (nrIncompleteClosure > 0 && nrIncompleteClosure == nrFailed) retrySubstitution = true;

nrFailed = nrNoSubstituters = nrIncompleteClosure = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/libstore/build/goal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct Goal : public std::enable_shared_from_this<Goal>
unsigned int nrNoSubstituters;

/* Number of substitution goals we are/were waiting for that
failed because othey had unsubstitutable references. */
failed because they had unsubstitutable references. */
unsigned int nrIncompleteClosure;

/* Name of this goal for debugging purposes. */
Expand Down
34 changes: 34 additions & 0 deletions tests/binary-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,37 @@ nix copy --to "file://$cacheDir?index-debug-info=1&compression=none" $outPath
diff -u \
<(cat $cacheDir/debuginfo/02623eda209c26a59b1a8638ff7752f6b945c26b.debug | jq -S) \
<(echo '{"archive":"../nar/100vxs724qr46phz8m24iswmg9p3785hsyagz0kchf6q6gf06sw6.nar","member":"lib/debug/.build-id/02/623eda209c26a59b1a8638ff7752f6b945c26b.debug"}' | jq -S)

# Test against issue https://github.com/NixOS/nix/issues/3964
#
expr='
with import ./config.nix;
mkDerivation {
name = "multi-output";
buildCommand = "mkdir -p $out; echo foo > $doc; echo $doc > $out/docref";
outputs = ["out" "doc"];
}
'
outPath=$(nix-build --no-out-link -E "$expr")
docPath=$(nix-store -q --references $outPath)

# $ nix-store -q --tree $outPath
# ...-multi-output
# +---...-multi-output-doc

nix copy --to "file://$cacheDir" $outPath
( echo $outPath $docPath
find $cacheDir
) >/tmp/blurb

hashpart() {
basename "$1" | cut -c1-32
}

# break the closure of out by removing doc
rm $cacheDir/$(hashpart $docPath).narinfo

nix-store --delete $outPath $docPath
# -vvv is the level that logs during the loop
timeout 60 nix-build -E "$expr" --option substituters "file://$cacheDir" \
--option trusted-binary-caches "file://$cacheDir" --no-require-sigs

0 comments on commit 67cc94b

Please sign in to comment.