Skip to content

Commit

Permalink
Try to realise CA derivations during queryMissing
Browse files Browse the repository at this point in the history
This enables nix to correctly report what will be fetched in the case
that everything is a cache hit.

Note however that if an intermediate build of something which is not
cached could still cause products to end up being substituted if the
intermediate build results in a CA path which is in the cache.

Fixes #8615.

Signed-off-by: Peter Waller <p@pwaller.net>
  • Loading branch information
pwaller committed Jul 1, 2023
1 parent a0c6173 commit 22651f7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/libstore/misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,40 @@ void Store::queryMissing(const std::vector<DerivedPath> & targets,
auto drv = make_ref<Derivation>(derivationFromPath(bfd.drvPath));
ParsedDerivation parsedDrv(StorePath(bfd.drvPath), *drv);

if (!knownOutputPaths && settings.useSubstitutes && parsedDrv.substitutesAllowed()) {
// Try to realise the static output hashes.

// TODO: I'm not sure this logic is quite right, how do we
// ensure all the needed paths are present?

// TODO: Should we also do this->queryRealisation?

// TODO: Originally, this was only done if the drv was a CA drv.
// But you could have a non-CA drv with a CA input. So it may be
// necessary to gate this on the CA experimental feature?
auto outputHashes = staticOutputHashes(*this, *drv);
knownOutputPaths = true;

for (auto [outputName, hash] : outputHashes) {
if (!bfd.outputs.contains(outputName))
continue;

bool found = false;
for (auto &sub : getDefaultSubstituters()) {
auto realisation = sub->queryRealisation({hash, outputName});
if (!realisation)
continue;
invalid.insert(realisation->outPath);
found = true;
}
if (!found) {
knownOutputPaths = false;
break;
}
}
}


if (knownOutputPaths && settings.useSubstitutes && parsedDrv.substitutesAllowed()) {
auto drvState = make_ref<Sync<DrvState>>(DrvState(invalid.size()));
for (auto & output : invalid)
Expand Down
8 changes: 8 additions & 0 deletions tests/ca/content-addressed.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ rec {
echo ${rootCA}/non-ca-hello > $out/dep
'';
};
noRuntimeDep = mkDerivation {
name = "no-runtime-dep";
buildCommand = ''
mkdir -p $out
echo ${rootCA}
touch $out
'';
};
dependentFixedOutput = mkDerivation {
name = "dependent-fixed-output";
outputHashMode = "recursive";
Expand Down

0 comments on commit 22651f7

Please sign in to comment.