···
1
+
{ config, lib, pkgs, ... }:
6
+
cfg = config.services.monero;
7
+
dataDir = "/var/lib/monero";
9
+
listToConf = option: list:
10
+
concatMapStrings (value: "${option}=${value}\n") list;
12
+
login = (cfg.rpc.user != null && cfg.rpc.password != null);
14
+
configFile = with cfg; pkgs.writeText "monero.conf" ''
15
+
log-file=/dev/stdout
18
+
${optionalString mining.enable ''
19
+
start-mining=${mining.address}
20
+
mining-threads=${toString mining.threads}
23
+
rpc-bind-ip=${rpc.address}
24
+
rpc-bind-port=${toString rpc.port}
25
+
${optionalString login ''
26
+
rpc-login=${rpc.user}:${rpc.password}
28
+
${optionalString rpc.restricted ''
32
+
limit-rate-up=${toString limits.upload}
33
+
limit-rate-down=${toString limits.download}
34
+
max-concurrency=${toString limits.threads}
35
+
block-sync-size=${toString limits.syncSize}
37
+
${listToConf "add-peer" extraNodes}
38
+
${listToConf "add-priority-node" priorityNodes}
39
+
${listToConf "add-exclusive-node" exclusiveNodes}
54
+
enable = mkEnableOption "Monero node daemon.";
56
+
mining.enable = mkOption {
60
+
Whether to mine moneroj.
64
+
mining.address = mkOption {
68
+
Monero address where to send mining rewards.
72
+
mining.threads = mkOption {
73
+
type = types.addCheck types.int (x: x>=0);
76
+
Number of threads used for mining.
77
+
Set to <literal>0</literal> to use all available.
81
+
rpc.user = mkOption {
82
+
type = types.nullOr types.str;
85
+
User name for RPC connections.
89
+
rpc.password = mkOption {
93
+
Password for RPC connections.
97
+
rpc.address = mkOption {
99
+
default = "127.0.0.1";
101
+
IP address the RPC server will bind to.
105
+
rpc.port = mkOption {
109
+
Port the RPC server will bind to.
113
+
rpc.restricted = mkOption {
117
+
Whether to restrict RPC to view only commands.
121
+
limits.upload = mkOption {
122
+
type = types.addCheck types.int (x: x>=-1);
125
+
Limit of the upload rate in kB/s.
126
+
Set to <literal>-1</literal> to leave unlimited.
130
+
limits.download = mkOption {
131
+
type = types.addCheck types.int (x: x>=-1);
134
+
Limit of the download rate in kB/s.
135
+
Set to <literal>-1</literal> to leave unlimited.
139
+
limits.threads = mkOption {
140
+
type = types.addCheck types.int (x: x>=0);
143
+
Maximum number of threads used for a parallel job.
144
+
Set to <literal>0</literal> to leave unlimited.
148
+
limits.syncSize = mkOption {
149
+
type = types.addCheck types.int (x: x>=0);
152
+
Maximum number of blocks to sync at once.
153
+
Set to <literal>0</literal> for adaptive.
157
+
extraNodes = mkOption {
158
+
type = types.listOf types.str;
161
+
List of additional peer IP addresses to add to the local list.
165
+
priorityNodes = mkOption {
166
+
type = types.listOf types.str;
169
+
List of peer IP addresses to connect to and
170
+
attempt to keep the connection open.
174
+
exclusiveNodes = mkOption {
175
+
type = types.listOf types.str;
178
+
List of peer IP addresses to connect to *only*.
179
+
If given the other peer options will be ignored.
183
+
extraConfig = mkOption {
184
+
type = types.lines;
187
+
Extra lines to be added verbatim to monerod configuration.
196
+
###### implementation
198
+
config = mkIf cfg.enable {
200
+
users.extraUsers = singleton {
202
+
uid = config.ids.uids.monero;
203
+
description = "Monero daemon user";
208
+
users.extraGroups = singleton {
210
+
gid = config.ids.gids.monero;
213
+
systemd.services.monero = {
214
+
description = "monero daemon";
215
+
after = [ "network.target" ];
216
+
wantedBy = [ "multi-user.target" ];
221
+
ExecStart = "${pkgs.monero}/bin/monerod --config-file=${configFile} --non-interactive";
222
+
Restart = "always";
223
+
SuccessExitStatus = [ 0 1 ];
227
+
assertions = singleton {
228
+
assertion = cfg.mining.enable -> cfg.mining.address != "";
230
+
You need a Monero address to receive mining rewards:
231
+
specify one using option monero.mining.address.