forked from makerdao/dss-deploy-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dapp2.nix
50 lines (43 loc) · 1.34 KB
/
dapp2.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
40
41
42
43
44
45
46
47
48
49
50
{ solidityPackage, solc, dapp2 }:
let
inherit (builtins) map listToAttrs attrNames attrValues length fromJSON readFile;
mapAttrs = if (builtins ? mapAttrs)
then builtins.mapAttrs
else f: attrs:
listToAttrs (map
(name: { inherit name; value = f name attrs."${name}"; })
(attrNames attrs));
defaults = {
inherit solc;
test-hevm = dapp2.test-hevm;
doCheck = true;
};
package = spec: let
spec' = defaults // (removeAttrs spec [ "repo" "repo'" "src'" ]);
deps = map (spec:
package (spec // { inherit (spec') solc test-hevm doCheck; })
) (attrValues spec'.deps);
in solidityPackage (spec' // { inherit deps; });
packageSpecs = mapAttrs (_: package);
jsonSpecs = fromJSON (readFile ./.dapp.json);
resolveDeps = _: v:
let
contract = jsonSpecs.contracts."${v}";
contract' = contract // {
src = "${fetchGit contract.repo}/src";
};
noDeps = length (attrNames contract.deps) == 0;
in
if noDeps
then contract'
else contract' // { deps = mapAttrs resolveDeps contract.deps; };
specs = (mapAttrs resolveDeps jsonSpecs.contracts) // {
this = jsonSpecs.this // {
deps = mapAttrs resolveDeps jsonSpecs.this.deps;
};
};
in {
inherit package packageSpecs specs;
this = package specs.this;
deps = packageSpecs specs.this.deps;
}