-
Notifications
You must be signed in to change notification settings - Fork 61
/
dapp2.nix
49 lines (42 loc) · 1.29 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
{ solidityPackage, solc }:
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;
doCheck = false;
};
package = spec: let
spec' = defaults // (removeAttrs spec [ "repo" "repo'" "src'" ]);
deps = map (spec:
package (spec // { inherit (spec') solc 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;
}