/
default.nix
140 lines (109 loc) · 3.31 KB
/
default.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
{ pkgs
, lib, jq, runCommand
, db-analyser
, cardanoNodePackages
, cardano-world
}:
with lib;
let
workbench' = tools:
pkgs.stdenv.mkDerivation {
pname = "workbench";
version = "0.1";
src = ./.;
buildInputs = with pkgs; [ jq makeWrapper ];
buildPhase = ''
patchShebangs .
'';
postFixup = ''
wrapProgram "$out/bin/wb" --argv0 wb --prefix PATH ":" ${makeBinPath tools}
'';
installPhase = ''
mkdir -p $out/bin
cp -a wb chain-filters profiles *.sh *.jq $out/bin
'';
dontStrip = true;
};
workbench = with cardanoNodePackages; with pkgs; workbench' (
[ git graphviz
jq yq
moreutils
procps
cardano-cli
cardano-topology
] ++ lib.optional (!pkgs.stdenv.hostPlatform.isDarwin) db-analyser ++ [
locli
]);
runWorkbench =
name: command:
runCommand name {} ''
${workbench}/bin/wb ${command} > $out
'';
runWorkbenchJqOnly =
name: command:
runCommand name {} ''
${workbench' (with pkgs; [jq moreutils])}/bin/wb ${command} > $out
'';
runJq =
name: args: query:
runCommand name {} ''
args=(${args})
${jq}/bin/jq '${query}' "''${args[@]}" > $out
'';
profile-names-json =
runWorkbenchJqOnly "profile-names.json" "profiles list";
profile-names =
__fromJSON (__readFile profile-names-json);
all-profiles =
## The backend is an attrset of AWS/supervisord-specific methods and parameters.
{ backend
## Environment arguments:
## - either affect semantics on all backends equally,
## - or have no semantic effect
, envArgs
}:
rec {
mkProfile =
profileName:
pkgs.callPackage ./profiles
{ inherit
pkgs
runWorkbenchJqOnly runJq workbench
backend
profileName;
};
value = genAttrs profile-names mkProfile;
JSON = pkgs.writeText "all-profiles.json" (__toJSON (mapAttrs (_: x: x.value) value));
};
## materialise-profile :: ProfileNix -> BackendProfile -> Profile
materialise-profile = import ./profile.nix { inherit pkgs lib cardano-world; };
## profile-topology :: ProfileNix -> Topology
profile-topology = import ./topology.nix { inherit pkgs; };
## profile-topology :: ProfileNix -> Topology -> Genesis
profile-topology-genesis = import ./genesis.nix { inherit pkgs; };
with-profile =
{ backend, envArgs, profileName }:
let
ps = all-profiles { inherit backend envArgs; };
profileNix = ps.value."${profileName}"
or (throw "No such profile: ${profileName}; Known profiles: ${toString (__attrNames ps.value)}");
profile = materialise-profile
{ inherit profileNix workbench;
backendProfile =
backend.materialise-profile { inherit profileNix; };
};
topology = profile-topology { inherit profileNix profile; };
genesis = profile-topology-genesis { inherit profile; };
in {
inherit
profileNix profile
topology
genesis;
};
run-analysis = import ./analyse.nix;
in {
inherit runJq;
inherit workbench' workbench runWorkbench runWorkbenchJqOnly;
inherit all-profiles profile-names profile-names-json with-profile;
inherit run-analysis;
}