Skip to content

Commit a1127e9

Browse files
committed
DrvOutputSubstitutionGoal: Don't actually fetch any store objects
We now have a nice separation of concerns: `DrvOutputSubstitutionGoal` is *just* for getting realisations, and `PathSubstitutionGoal` is just for fetching store objects. The fetching of store objects that this used to do is now moved to the caller.
1 parent 0c33c8d commit a1127e9

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

src/libstore/build/derivation-goal.cc

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "nix/store/build/derivation-goal.hh"
2+
#include "nix/store/build/drv-output-substitution-goal.hh"
23
#include "nix/store/build/derivation-building-goal.hh"
34
#include "nix/store/build/derivation-resolution-goal.hh"
45
#ifndef _WIN32 // TODO enable build hook on Windows
@@ -100,9 +101,24 @@ Goal::Co DerivationGoal::haveDerivation(bool storeDerivation)
100101
through substitutes. If that doesn't work, we'll build
101102
them. */
102103
if (settings.useSubstitutes && drvOptions.substitutesAllowed()) {
103-
if (!checkResult)
104-
waitees.insert(upcast_goal(worker.makeDrvOutputSubstitutionGoal(DrvOutput{outputHash, wantedOutput})));
105-
else {
104+
if (!checkResult) {
105+
DrvOutput id{outputHash, wantedOutput};
106+
auto g = worker.makeDrvOutputSubstitutionGoal(id);
107+
waitees.insert(g);
108+
co_await await(std::move(waitees));
109+
110+
if (nrFailed == 0) {
111+
waitees.insert(upcast_goal(worker.makePathSubstitutionGoal(g->outputInfo->outPath)));
112+
co_await await(std::move(waitees));
113+
114+
trace("output path substituted");
115+
116+
if (nrFailed == 0)
117+
worker.store.registerDrvOutput({*g->outputInfo, id});
118+
else
119+
debug("The output path of the derivation output '%s' could not be substituted", id.to_string());
120+
}
121+
} else {
106122
auto * cap = getDerivationCA(*drv);
107123
waitees.insert(upcast_goal(worker.makePathSubstitutionGoal(
108124
checkResult->first.outPath,

src/libstore/build/drv-output-substitution-goal.cc

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Goal::Co DrvOutputSubstitutionGoal::init()
2121
trace("init");
2222

2323
/* If the derivation already exists, we’re done */
24-
if (worker.store.queryRealisation(id)) {
24+
if ((outputInfo = worker.store.queryRealisation(id))) {
2525
co_return amDone(ecSuccess);
2626
}
2727

@@ -70,12 +70,6 @@ Goal::Co DrvOutputSubstitutionGoal::init()
7070

7171
worker.childTerminated(this);
7272

73-
/*
74-
* The realisation corresponding to the given output id.
75-
* Will be filled once we can get it.
76-
*/
77-
std::shared_ptr<const UnkeyedRealisation> outputInfo;
78-
7973
try {
8074
outputInfo = promise->get_future().get();
8175
} catch (std::exception & e) {
@@ -86,21 +80,6 @@ Goal::Co DrvOutputSubstitutionGoal::init()
8680
if (!outputInfo)
8781
continue;
8882

89-
Goals waitees;
90-
91-
waitees.insert(worker.makePathSubstitutionGoal(outputInfo->outPath));
92-
93-
co_await await(std::move(waitees));
94-
95-
trace("output path substituted");
96-
97-
if (nrFailed > 0) {
98-
debug("The output path of the derivation output '%s' could not be substituted", id.to_string());
99-
co_return amDone(nrNoSubstituters > 0 ? ecNoSubstituters : ecFailed);
100-
}
101-
102-
worker.store.registerDrvOutput({*outputInfo, id});
103-
10483
trace("finished");
10584
co_return amDone(ecSuccess);
10685
}

src/libstore/include/nix/store/build/drv-output-substitution-goal.hh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ namespace nix {
1414
class Worker;
1515

1616
/**
17-
* Substitution of a derivation output.
18-
* This is done in three steps:
19-
* 1. Fetch the output info from a substituter
20-
* 2. Substitute the corresponding output path
21-
* 3. Register the output info
17+
* Fetch a `Realisation` (drv ⨯ output name -> output path) from a
18+
* substituter.
19+
*
20+
* If the output store object itself should also be substituted, that is
21+
* the responsibility of the caller to do so.
2222
*/
2323
class DrvOutputSubstitutionGoal : public Goal
2424
{
@@ -31,6 +31,12 @@ class DrvOutputSubstitutionGoal : public Goal
3131
public:
3232
DrvOutputSubstitutionGoal(const DrvOutput & id, Worker & worker);
3333

34+
/**
35+
* The realisation corresponding to the given output id.
36+
* Will be filled once we can get it.
37+
*/
38+
std::shared_ptr<const UnkeyedRealisation> outputInfo;
39+
3440
Co init();
3541

3642
void timedOut(Error && ex) override

0 commit comments

Comments
 (0)