-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathanvil.nix
More file actions
109 lines (97 loc) · 3.02 KB
/
Copy pathanvil.nix
File metadata and controls
109 lines (97 loc) · 3.02 KB
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
{
pkgs,
lib,
name,
config,
...
}: {
options = {
package = lib.mkOption {
type = lib.types.package;
description = "Foundry package containing anvil";
};
port = lib.mkOption {
type = lib.types.port;
default = 8545;
description = "Port for Anvil RPC server";
};
timestamp = lib.mkOption {
type = lib.types.int;
default = 1743944919;
description = "Timestamp for the genesis block";
};
gasLimit = lib.mkOption {
type = lib.types.int;
default = 100000000000;
description = "Gas limit for the genesis block";
};
baseFee = lib.mkOption {
type = lib.types.int;
default = 1;
description = "Base fee for the genesis block";
};
blockTime = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
description = "Block time in seconds. Null means instant mining.";
};
state = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "Path to state file (loads on start, saves on exit)";
};
stateInterval = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
description = "Interval in seconds to dump state to disk. Useful when graceful shutdown isn't guaranteed.";
};
preserveHistoricalStates = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Preserve historical state snapshots when dumping. Enables RPC calls for older blocks after state reload.";
};
};
config = {
outputs.settings.processes.${name} = {
command = let
stateDir =
if config.state != null
then builtins.dirOf config.state
else null;
mkdirCmd =
if stateDir != null
then "mkdir -p ${stateDir} && "
else "";
in
mkdirCmd
+ builtins.concatStringsSep " " (lib.filter (s: s != "") [
"${lib.getExe' config.package "anvil"}"
"--gas-limit ${toString config.gasLimit}"
"--base-fee ${toString config.baseFee}"
"--timestamp ${toString config.timestamp}"
"--port ${toString config.port}"
(lib.optionalString (config.blockTime != null) "--block-time ${toString config.blockTime}")
(lib.optionalString (config.state != null) "--state ${config.state}")
(lib.optionalString (config.stateInterval != null) "--state-interval ${toString config.stateInterval}")
(lib.optionalString config.preserveHistoricalStates "--preserve-historical-states")
]);
availability = {
restart = "on_failure";
};
shutdown = {
command = "kill -TERM $${PROCESS_PID}";
timeout_seconds = 10;
};
readiness_probe = {
exec = {
command = "nc -z localhost ${toString config.port}";
};
initial_delay_seconds = 3;
period_seconds = 2;
timeout_seconds = 5;
success_threshold = 1;
failure_threshold = 10;
};
};
};
}