-
Notifications
You must be signed in to change notification settings - Fork 11
/
force_cached.nix
39 lines (34 loc) · 1006 Bytes
/
force_cached.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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; exit 0" ];
}
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