Skip to content

Commit 50912d0

Browse files
Ericson2314fogti
andcommitted
Get rid of impureOutputHash
I do not believe there is any problem with computing `hashDerivationModulo` the normal way with impure derivations. Conversely, the way this used to work is very suspicious because two almost-equal derivations that only differ in depending on different impure derivations could have the same drv hash modulo. That is very suspicious because there is no reason to think those two different impure derivations will end up producing the same content-addressed data! Co-authored-by: Alain Zscheile <[email protected]>
1 parent 23259bd commit 50912d0

File tree

3 files changed

+32
-41
lines changed

3 files changed

+32
-41
lines changed

src/libstore/build/derivation-goal.cc

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -185,41 +185,44 @@ Goal::Co DerivationGoal::haveDerivation()
185185
if (!drv->type().hasKnownOutputPaths())
186186
experimentalFeatureSettings.require(Xp::CaDerivations);
187187

188-
if (drv->type().isImpure()) {
189-
experimentalFeatureSettings.require(Xp::ImpureDerivations);
190-
191-
for (auto & [outputName, output] : drv->outputs) {
192-
auto randomPath = StorePath::random(outputPathName(drv->name, outputName));
193-
assert(!worker.store.isValidPath(randomPath));
194-
initialOutputs.insert({
195-
outputName,
196-
InitialOutput {
197-
.wanted = true,
198-
.outputHash = impureOutputHash,
199-
.known = InitialOutputStatus {
200-
.path = randomPath,
201-
.status = PathStatus::Absent
202-
}
203-
}
204-
});
205-
}
206-
207-
co_return gaveUpOnSubstitution();
208-
}
209-
210188
for (auto & i : drv->outputsAndOptPaths(worker.store))
211189
if (i.second.second)
212190
worker.store.addTempRoot(*i.second.second);
213191

214-
auto outputHashes = staticOutputHashes(worker.evalStore, *drv);
215-
for (auto & [outputName, outputHash] : outputHashes)
216-
initialOutputs.insert({
217-
outputName,
218-
InitialOutput {
192+
{
193+
bool impure = drv->type().isImpure();
194+
195+
if (impure) experimentalFeatureSettings.require(Xp::ImpureDerivations);
196+
197+
auto outputHashes = staticOutputHashes(worker.evalStore, *drv);
198+
for (auto & [outputName, outputHash] : outputHashes) {
199+
InitialOutput v{
219200
.wanted = true, // Will be refined later
220201
.outputHash = outputHash
202+
};
203+
204+
/* TODO we might want to also allow randomizing the paths
205+
for regular CA derivations, e.g. for sake of checking
206+
determinism. */
207+
if (impure) {
208+
v.known = InitialOutputStatus {
209+
.path = StorePath::random(outputPathName(drv->name, outputName)),
210+
.status = PathStatus::Absent,
211+
};
221212
}
222-
});
213+
214+
initialOutputs.insert({
215+
outputName,
216+
std::move(v),
217+
});
218+
}
219+
220+
if (impure) {
221+
/* We don't yet have any safe way to cache an impure derivation at
222+
this step. */
223+
co_return gaveUpOnSubstitution();
224+
}
225+
}
223226

224227
{
225228
/* Check what outputs paths are not already valid. */

src/libstore/derivations.cc

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -843,16 +843,6 @@ DrvHash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOut
843843
};
844844
}
845845

846-
if (type.isImpure()) {
847-
std::map<std::string, Hash> outputHashes;
848-
for (const auto & [outputName, _] : drv.outputs)
849-
outputHashes.insert_or_assign(outputName, impureOutputHash);
850-
return DrvHash {
851-
.hashes = outputHashes,
852-
.kind = DrvHash::Kind::Deferred,
853-
};
854-
}
855-
856846
auto kind = std::visit(overloaded {
857847
[](const DerivationType::InputAddressed & ia) {
858848
/* This might be a "pesimistically" deferred output, so we don't
@@ -865,7 +855,7 @@ DrvHash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOut
865855
: DrvHash::Kind::Deferred;
866856
},
867857
[](const DerivationType::Impure &) -> DrvHash::Kind {
868-
assert(false);
858+
return DrvHash::Kind::Deferred;
869859
}
870860
}, drv.type().raw);
871861

src/libstore/derivations.hh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,4 @@ void writeDerivation(Sink & out, const StoreDirConfig & store, const BasicDeriva
526526
*/
527527
std::string hashPlaceholder(const OutputNameView outputName);
528528

529-
extern const Hash impureOutputHash;
530-
531529
}

0 commit comments

Comments
 (0)