Don't substitute derivations that have preferLocalBuild set
In particular this means that "trivial" derivations such as writeText are not substituted, reducing the number of GET requests to the binary cache by about 200 on a typical NixOS configuration.
This commit is contained in:
parent
1906cce6fc
commit
5558652709
|
@ -1072,7 +1072,7 @@ void DerivationGoal::haveDerivation()
|
||||||
/* We are first going to try to create the invalid output paths
|
/* We are first going to try to create the invalid output paths
|
||||||
through substitutes. If that doesn't work, we'll build
|
through substitutes. If that doesn't work, we'll build
|
||||||
them. */
|
them. */
|
||||||
if (settings.useSubstitutes)
|
if (settings.useSubstitutes && !willBuildLocally(drv))
|
||||||
foreach (PathSet::iterator, i, invalidOutputs)
|
foreach (PathSet::iterator, i, invalidOutputs)
|
||||||
addWaitee(worker.makeSubstitutionGoal(*i, repair));
|
addWaitee(worker.makeSubstitutionGoal(*i, repair));
|
||||||
|
|
||||||
|
@ -1273,6 +1273,12 @@ static bool canBuildLocally(const string & platform)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool willBuildLocally(Derivation & drv)
|
||||||
|
{
|
||||||
|
return drv.env["preferLocalBuild"] == "1" && canBuildLocally(drv.platform);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DerivationGoal::tryToBuild()
|
void DerivationGoal::tryToBuild()
|
||||||
{
|
{
|
||||||
trace("trying to build");
|
trace("trying to build");
|
||||||
|
@ -1337,11 +1343,10 @@ void DerivationGoal::tryToBuild()
|
||||||
|
|
||||||
/* Don't do a remote build if the derivation has the attribute
|
/* Don't do a remote build if the derivation has the attribute
|
||||||
`preferLocalBuild' set. */
|
`preferLocalBuild' set. */
|
||||||
bool preferLocalBuild =
|
bool buildLocally = willBuildLocally(drv);
|
||||||
drv.env["preferLocalBuild"] == "1" && canBuildLocally(drv.platform);
|
|
||||||
|
|
||||||
/* Is the build hook willing to accept this job? */
|
/* Is the build hook willing to accept this job? */
|
||||||
if (!preferLocalBuild) {
|
if (!buildLocally) {
|
||||||
switch (tryBuildHook()) {
|
switch (tryBuildHook()) {
|
||||||
case rpAccept:
|
case rpAccept:
|
||||||
/* Yes, it has started doing so. Wait until we get
|
/* Yes, it has started doing so. Wait until we get
|
||||||
|
@ -1364,7 +1369,7 @@ void DerivationGoal::tryToBuild()
|
||||||
derivation prefers to be done locally, do it even if
|
derivation prefers to be done locally, do it even if
|
||||||
maxBuildJobs is 0. */
|
maxBuildJobs is 0. */
|
||||||
unsigned int curBuilds = worker.getNrLocalBuilds();
|
unsigned int curBuilds = worker.getNrLocalBuilds();
|
||||||
if (curBuilds >= settings.maxBuildJobs && !(preferLocalBuild && curBuilds == 0)) {
|
if (curBuilds >= settings.maxBuildJobs && !(buildLocally && curBuilds == 0)) {
|
||||||
worker.waitForBuildSlot(shared_from_this());
|
worker.waitForBuildSlot(shared_from_this());
|
||||||
outputLocks.unlock();
|
outputLocks.unlock();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -120,7 +120,8 @@ void queryMissing(StoreAPI & store, const PathSet & targets,
|
||||||
if (invalid.empty()) continue;
|
if (invalid.empty()) continue;
|
||||||
|
|
||||||
todoDrv.insert(*i);
|
todoDrv.insert(*i);
|
||||||
if (settings.useSubstitutes) query.insert(invalid.begin(), invalid.end());
|
if (settings.useSubstitutes && !willBuildLocally(drv))
|
||||||
|
query.insert(invalid.begin(), invalid.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
@ -143,7 +144,7 @@ void queryMissing(StoreAPI & store, const PathSet & targets,
|
||||||
|
|
||||||
PathSet outputs;
|
PathSet outputs;
|
||||||
bool mustBuild = false;
|
bool mustBuild = false;
|
||||||
if (settings.useSubstitutes) {
|
if (settings.useSubstitutes && !willBuildLocally(drv)) {
|
||||||
foreach (DerivationOutputs::iterator, j, drv.outputs) {
|
foreach (DerivationOutputs::iterator, j, drv.outputs) {
|
||||||
if (!wantOutput(j->first, i2.second)) continue;
|
if (!wantOutput(j->first, i2.second)) continue;
|
||||||
if (!store.isValidPath(j->second.path)) {
|
if (!store.isValidPath(j->second.path)) {
|
||||||
|
|
|
@ -32,5 +32,7 @@ void queryMissing(StoreAPI & store, const PathSet & targets,
|
||||||
PathSet & willBuild, PathSet & willSubstitute, PathSet & unknown,
|
PathSet & willBuild, PathSet & willSubstitute, PathSet & unknown,
|
||||||
unsigned long long & downloadSize, unsigned long long & narSize);
|
unsigned long long & downloadSize, unsigned long long & narSize);
|
||||||
|
|
||||||
|
bool willBuildLocally(Derivation & drv);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue