-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
allowSubstitutes = false
example
- Loading branch information
Showing
3 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ coreutils }: | ||
|
||
attrs: | ||
with builtins; | ||
let | ||
# Copied from <nixpkgs/lib> | ||
isDerivation = x: isAttrs x && x ? type && x.type == "derivation"; | ||
|
||
# Return true if `nix-build` would traverse that attribute set to look for | ||
# more derivations to build. | ||
hasRecurseIntoAttrs = x: isAttrs x && (x.recurseForDerivations or false); | ||
|
||
# Wraps derivations that disallow substitutes so that they can be cached. | ||
toCachedDrv = drv: | ||
if !(drv.allowSubstitutes or true) then | ||
derivation | ||
{ | ||
name = "${drv.name}-to-cached"; | ||
system = drv.system; | ||
builder = "/bin/sh"; | ||
args = [ "-c" "${coreutils}/bin/ln -s ${drv} $out" ]; | ||
} | ||
else | ||
drv; | ||
|
||
op = _: val: | ||
if isDerivation val then | ||
toCachedDrv val | ||
else if hasRecurseIntoAttrs val then | ||
forceCached val | ||
else | ||
val | ||
; | ||
|
||
# Traverses a tree of derivation and wrap all of those that disallow | ||
# substitutes. | ||
forceCached = attrs: mapAttrs op attrs; | ||
in | ||
forceCached attrs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
let | ||
pkgs = import <nixpkgs> {}; | ||
in (pkgs.callPackage ./force_cached.nix {}) { | ||
hello = pkgs.writeScriptBin "hello" '' | ||
#!/bin/sh | ||
exec ${pkgs.hello}/bin/hello | ||
''; | ||
} |