/
cardano-wallet-service.nix
193 lines (171 loc) · 6.28 KB
/
cardano-wallet-service.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
{ config, lib, pkgs, ... }:
let
cfg = config.services.cardano-wallet;
inherit (lib) optionalString mkIf mkEnableOption mkOption types;
logLevels = types.enum [ "debug" "info" "notice" "warning" "error" "critical" "alert" "emergency" "off" ];
cardanoEnvAttrs = cfg.environments.${cfg.environment};
in
{
options.services.cardano-wallet = {
enable = mkEnableOption "Cardano Wallet service";
script = mkOption {
type = types.str;
internal = true;
default =
let
genesisFile = cardanoEnvAttrs.genesisFile
or cardanoEnvAttrs.nodeConfig.ByronGenesisFile;
in
toString ([
"exec ${cfg.package}/bin/cardano-wallet serve"
"--listen-address \"${cfg.listenAddress}\""
"--port ${toString cfg.port}"
"--node-socket \"$CARDANO_NODE_SOCKET_PATH\""
"--sync-tolerance ${toString cfg.syncTolerance}s"
"--pool-metadata-fetching ${if (cfg.poolMetadataFetching == "smash")
then cardanoEnvAttrs.smashUrl
else cfg.poolMetadataFetching}"
"--log-level ${cfg.logLevel}"
"--${cfg.walletMode}"
] ++ lib.optional (cfg.walletMode != "mainnet")
"\"${genesisFile}\""
++ lib.optional (cfg.tokenMetadataServer != null)
"--token-metadata-server ${cfg.tokenMetadataServer}"
++ lib.optional (cfg.database != null)
"--database \"${cfg.database}\""
++ lib.mapAttrsToList
(name: level: ''
--trace-${name}=${level} '')
cfg.trace
++ cfg.rtsArgs)
;
};
project = mkOption {
type = types.attrs;
default = (import ../.. { }).legacyPackages.${pkgs.system};
description = "The cardano-wallet haskell.nix project attribute set.";
};
package = mkOption {
type = types.package;
default = cfg.project.hsPkgs.cardano-wallet.components.exes.cardano-wallet;
description = "Package for the cardano wallet executable.";
};
listenAddress = mkOption {
type = types.str;
default = "*";
description = "Which host to bind the API server to.";
};
port = mkOption {
type = types.port;
default = 8090;
description = "The default port cardano wallet will listen on.";
};
nodeSocket = mkOption {
type = types.str;
default = "/run/cardano-node/node.socket";
description = ''Cardano-Node local communication socket path.'';
};
environment = mkOption {
type = types.enum (builtins.attrNames cfg.environments);
default = "testnet";
description = ''
The environment name to configure the wallet for.
This name can be an environment name from those found at
iohk-nix/cardano-lib/default.nix, or, it can be a custom
name, for example, if launching a test cluster that does
not have an environment yet defined in iohk-nix. If custom,
the environments option must contain an entry for this environment,
of the same form as in cardano-lib environments found
in iohk-nix.
'';
};
environments = mkOption {
type = types.attrsOf types.attrs;
default = cfg.project.pkgs.cardanoLib.environments;
description = ''
The set of possible environment attribute set to configure the wallet for.
Default to the set of environments found at
iohk-nix/cardano-lib/default.nix, or, it must be an attribute set
of the same form.
'';
};
walletMode = mkOption {
type = types.enum [ "mainnet" "staging" "testnet" ];
default =
if cfg.environment == "mainnet"
then "mainnet"
else if cfg.environment == "staging"
then "staging"
else "testnet";
description = "Which mode to start wallet in: --mainnet, --staging or --testnet";
};
database = mkOption {
type = types.nullOr types.str;
default = "$STATE_DIRECTORY";
description = ''Directory for storing wallets. Run in-memory if null.'';
};
syncTolerance = mkOption {
type = types.ints.positive;
default = 300;
description = "Time duration within which we consider being synced with the network. Expressed in seconds.";
};
poolMetadataFetching = mkOption {
type = types.enum [ "none" "direct" "smash" ];
default = if cardanoEnvAttrs ? smashUrl then "smash" else "none";
description = ''
Sets the stake pool metadata fetching strategy.
"smash" will use the 'smashUrl' attribute of the 'environnement'
as metadata proxy server (default if exists).
Use "direct" to fetch directly from the
registered pool URLs, or "none" to completely disable
stake pool metadata (default if no 'smashUrl' defined).'';
};
tokenMetadataServer = mkOption {
type = types.nullOr types.str;
default = cardanoEnvAttrs.metadataUrl or null;
description = ''
Sets the URL of the token metadata server,
default to 'metadataUrl' of the 'environnement' attribute, if exists.
If unset, metadata will not be fetched. By using this
option, you are fully trusting the operator of the
metadata server to provide authentic token metadata.
'';
};
logLevel = mkOption {
type = logLevels;
default = "info";
description = "Global minimum severity for a message to be logged.";
};
trace = mkOption {
type = types.attrsOf logLevels;
default = { };
description = ''
For each tracer, minimum severity for a message to be logged, or
"off" to disable the tracer".
'';
};
rtsArgs = mkOption {
type = types.listOf types.str;
default = [ "-N2" ];
apply = args:
if args != [ ] then
[ "+RTS" ] ++ args ++ [ "-RTS" ]
else [ ];
description = ''Extra CLI args for 'cardano-wallet', to be surrounded by "+RTS"/"-RTS"'';
};
};
config = mkIf cfg.enable {
systemd.services.cardano-wallet = {
description = "cardano-wallet daemon";
wantedBy = [ "multi-user.target" ];
inherit (cfg) script;
serviceConfig = {
DynamicUser = true;
StateDirectory = "cardano-wallet/${cfg.environment}";
};
environment = {
CARDANO_NODE_SOCKET_PATH = cfg.nodeSocket;
};
};
};
}