forked from unionlabs/union
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhubble.nix
253 lines (250 loc) · 8.39 KB
/
hubble.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
{ self, ... }:
{
perSystem =
{
self',
pkgs,
crane,
...
}:
let
hubble = crane.buildWorkspaceMember {
crateDirFromRoot = "hubble";
cargoTestExtraAttrs = {
partitions = 1;
partitionType = "count";
};
extraEnv = {
SQLX_OFFLINE = "1";
};
};
in
{
inherit (hubble) checks;
packages = {
inherit (hubble.packages) hubble;
hubble-image = pkgs.dockerTools.buildLayeredImage {
name = "hubble";
contents = [
pkgs.coreutils-full
pkgs.cacert
self'.packages.hubble
];
config = {
Entrypoint = [ (pkgs.lib.getExe self'.packages.hubble) ];
Env = [ "SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" ];
};
};
};
};
flake.nixosModules.hubble =
{
lib,
pkgs,
config,
...
}:
with lib;
let
cfg = config.services.hubble;
in
{
options.services.hubble = {
enable = mkEnableOption "Hubble service";
package = mkOption {
type = types.package;
default = self.packages.${pkgs.system}.hubble;
};
metrics-addr = mkOption {
type = types.str;
default = "0.0.0.0:9090";
};
api-key-file = mkOption {
description = lib.mdDoc ''
Path to a file containing the database secret to allow for inserts.
'';
example = "/run/keys/hubble.key";
type = types.path;
default = "";
};
indexers = mkOption {
type = types.listOf (
types.submodule {
options.indexer_id = mkOption {
type = types.nullOr types.str;
description = "Id of the indexer which is used by the internal administration of Hubble. Should never change.";
example = "amazing-testnet";
default = null;
};
options.filter = mkOption {
type = types.nullOr types.str;
description = "A regex which if matches, removes the event from the insertion";
example = "coin_received";
default = null;
};
options.rpc_urls = mkOption {
type = types.nullOr (types.listOf types.str);
description = "List of rpc urls";
example = [ "https://rpc.example.com" ];
default = null;
};
options.grpc_urls = mkOption {
type = types.nullOr (types.listOf types.str);
description = "List of grpc urls";
example = [ "https://grpc.example.com" ];
default = null;
};
options.type = mkOption {
type = types.enum [
"ethereum"
"tendermint"
"aptos"
];
};
options.start_height = mkOption {
type = types.int;
example = 1;
default = 0;
};
options.chunk_size = mkOption {
type = types.int;
example = 1;
default = 200;
};
options.tx_search_max_page_size = mkOption {
type = types.int;
description = "Maximum number of transactions to fetch in one page";
example = 1;
default = 100;
};
options.finalizer = mkOption {
description = "control finalizer behavior";
example = {
reload = true;
delay_blocks = 5;
};
default = null;
type = types.nullOr (
types.submodule {
options = {
delay_blocks = mkOption {
type = types.nullOr types.int;
default = null;
description = "how many blocks to wait until a block is considered finalized (ie. there should be no reorgs). compensates for height differences between rpcs.";
};
reload = mkOption {
type = types.nullOr types.bool;
default = null;
description = "reload all block data after a block is considered finalized. compensates for rpcs returning inconsistent results for non-finalized blocks.";
};
min_seconds_between_monitor_checks = mkOption {
type = types.nullOr types.int;
default = null;
description = "minimum time (in seconds) between checking hash changes of non finalized blocks.";
};
retry_later_sleep_seconds = mkOption {
type = types.nullOr types.int;
default = null;
description = "sleep time (in seconds) when there is nothing to finalize.";
};
};
}
);
};
options.client_tracking = mkOption {
type = types.nullOr types.bool;
description = "control if client tracking is enabled. when enabled it automatically creates client entries which registers the counterparty chain of a client.";
example = true;
default = null;
};
}
);
};
log-level = mkOption {
type = types.str;
default = "info";
description = "RUST_LOG passed to hubble";
example = "hubble=debug";
};
backtrace = mkOption {
type = types.enum [
"0"
"1"
"full"
];
default = "1";
description = "RUST_BACKTRACE passed to hubble";
example = "full";
};
no-color = mkOption {
type = types.enum [
"0"
"1"
];
default = "1";
description = "NO_COLOR passed to hubble";
example = "1";
};
log-format = mkOption {
type = types.enum [
"json"
"plain"
];
default = "json";
example = "plain";
};
tokens_urls = mkOption {
type = types.nullOr (types.listOf types.str);
description = "List of tokenlist urls";
example = [ "https://static.optimism.io/optimism.tokenlist.json" ];
default = null;
};
};
config = mkIf cfg.enable {
systemd.services.hubble =
let
hubble-systemd-script = pkgs.writeShellApplication {
name = "hubble-systemd";
runtimeInputs = [
pkgs.coreutils
cfg.package
];
text =
let
# convert to json, removing null values
filterNullValues = lib.attrsets.filterAttrsRecursive (_n: v: v != null);
indexersWithoutNulls = map filterNullValues cfg.indexers;
indexersJson = builtins.toJSON indexersWithoutNulls;
tokensUrlsJson = builtins.toJSON cfg.tokens_urls;
in
''
${pkgs.lib.getExe cfg.package} \
--database-url "$(head -n 1 ${cfg.api-key-file})" \
--log-format ${cfg.log-format} \
--metrics-addr ${cfg.metrics-addr} \
--indexers '${indexersJson}' \
--tokens-urls '${tokensUrlsJson}'
'';
};
in
{
wantedBy = [ "multi-user.target" ];
description = "Hubble";
unitConfig = {
StartLimitIntervalSec = mkForce 0;
};
serviceConfig = {
Type = "simple";
ExecStart = pkgs.lib.getExe hubble-systemd-script;
Restart = mkForce "always";
RestartSec = mkForce 3;
};
environment = {
RUST_LOG = "${cfg.log-level}";
RUST_BACKTRACE = "${cfg.backtrace}";
NO_COLOR = "${cfg.no-color}";
};
};
};
};
}