Skip to content

Commit

Permalink
feat: add always-allow-substitutes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lovesegfault committed Mar 14, 2023
1 parent a387f46 commit 1ad8638
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/manual/src/language/advanced-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ Derivations can declare some infrequently used optional attributes.
useful for very trivial derivations (such as `writeText` in Nixpkgs)
that are cheaper to build than to substitute from a binary cache.

You may disable the effects of this attibute by enabling the
`always-allow-substitutes` configuration option in Nix.

> **Note**
>
> You need to have a builder configured which satisfies the
Expand Down
8 changes: 8 additions & 0 deletions src/libstore/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ public:
For the exact format and examples, see [the manual chapter on remote builds](../advanced-topics/distributed-builds.md)
)"};

Setting<bool> alwaysAllowSubstitutes{
this, false, "always-allow-substitutes",
R"(
If set to `true`, Nix will ignore the `allowSubstitutes` attribute in
derivations and always attempt to use available substituters.
For more information on `allowSubstitutes`, see [the manual chapter on advanced attributes](../language/advanced-attributes.md).
)"};

Setting<bool> buildersUseSubstitutes{
this, false, "builders-use-substitutes",
R"(
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/parsed-derivations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ bool ParsedDerivation::willBuildLocally(Store & localStore) const

bool ParsedDerivation::substitutesAllowed() const
{
return getBoolAttr("allowSubstitutes", true);
return settings.alwaysAllowSubstitutes ? true : getBoolAttr("allowSubstitutes", true);
}

bool ParsedDerivation::useUidRange() const
Expand Down

0 comments on commit 1ad8638

Please sign in to comment.