Skip to content

Commit 1ad8638

Browse files
committed
feat: add always-allow-substitutes
This adds a new configuration option to Nix, `always-allow-substitutes`, whose effect is simple: it causes the `allowSubstitutes` attribute in derivations to be ignored, and for substituters to always be used. This is extremely valuable for users of Nix in CI, where usually `nix-build-uncached` is used. There, derivations which disallow substitutes cause headaches as the inputs for building already-cached derivations need to be fetched to spuriously rebuild some simple text file. This option should be a good middle-ground, since it doesn't imply rebuilding the world, such as the approach I took in NixOS/nixpkgs#221048
1 parent a387f46 commit 1ad8638

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/manual/src/language/advanced-attributes.md

+3
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ Derivations can declare some infrequently used optional attributes.
248248
useful for very trivial derivations (such as `writeText` in Nixpkgs)
249249
that are cheaper to build than to substitute from a binary cache.
250250
251+
You may disable the effects of this attibute by enabling the
252+
`always-allow-substitutes` configuration option in Nix.
253+
251254
> **Note**
252255
>
253256
> You need to have a builder configured which satisfies the

src/libstore/globals.hh

+8
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ public:
219219
For the exact format and examples, see [the manual chapter on remote builds](../advanced-topics/distributed-builds.md)
220220
)"};
221221

222+
Setting<bool> alwaysAllowSubstitutes{
223+
this, false, "always-allow-substitutes",
224+
R"(
225+
If set to `true`, Nix will ignore the `allowSubstitutes` attribute in
226+
derivations and always attempt to use available substituters.
227+
For more information on `allowSubstitutes`, see [the manual chapter on advanced attributes](../language/advanced-attributes.md).
228+
)"};
229+
222230
Setting<bool> buildersUseSubstitutes{
223231
this, false, "builders-use-substitutes",
224232
R"(

src/libstore/parsed-derivations.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ bool ParsedDerivation::willBuildLocally(Store & localStore) const
122122

123123
bool ParsedDerivation::substitutesAllowed() const
124124
{
125-
return getBoolAttr("allowSubstitutes", true);
125+
return settings.alwaysAllowSubstitutes ? true : getBoolAttr("allowSubstitutes", true);
126126
}
127127

128128
bool ParsedDerivation::useUidRange() const

0 commit comments

Comments
 (0)