nixpkgs/nixos/modules/services/networking/monero.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

243 lines
5.8 KiB
Nix
Raw Normal View History

2018-02-05 21:02:14 +00:00
{ config, lib, pkgs, ... }:
let
cfg = config.services.monero;
listToConf = option: list:
2024-09-21 10:15:00 +00:00
lib.concatMapStrings (value: "${option}=${value}\n") list;
2018-02-05 21:02:14 +00:00
login = (cfg.rpc.user != null && cfg.rpc.password != null);
configFile = with cfg; pkgs.writeText "monero.conf" ''
log-file=/dev/stdout
data-dir=${dataDir}
2024-09-21 10:15:00 +00:00
${lib.optionalString mining.enable ''
2018-02-05 21:02:14 +00:00
start-mining=${mining.address}
mining-threads=${toString mining.threads}
''}
rpc-bind-ip=${rpc.address}
rpc-bind-port=${toString rpc.port}
2024-09-21 10:15:00 +00:00
${lib.optionalString login ''
2018-02-05 21:02:14 +00:00
rpc-login=${rpc.user}:${rpc.password}
''}
2024-09-21 10:15:00 +00:00
${lib.optionalString rpc.restricted ''
restricted-rpc=1
2018-02-05 21:02:14 +00:00
''}
limit-rate-up=${toString limits.upload}
limit-rate-down=${toString limits.download}
max-concurrency=${toString limits.threads}
block-sync-size=${toString limits.syncSize}
${listToConf "add-peer" extraNodes}
${listToConf "add-priority-node" priorityNodes}
${listToConf "add-exclusive-node" exclusiveNodes}
${extraConfig}
'';
in
{
###### interface
options = {
services.monero = {
2024-09-21 10:15:00 +00:00
enable = lib.mkEnableOption "Monero node daemon";
2018-02-05 21:02:14 +00:00
2024-09-21 10:15:00 +00:00
dataDir = lib.mkOption {
type = lib.types.str;
2021-05-04 21:12:54 +00:00
default = "/var/lib/monero";
description = ''
The directory where Monero stores its data files.
'';
};
2024-09-21 10:15:00 +00:00
mining.enable = lib.mkOption {
type = lib.types.bool;
2018-02-05 21:02:14 +00:00
default = false;
description = ''
2021-05-04 21:13:31 +00:00
Whether to mine monero.
2018-02-05 21:02:14 +00:00
'';
};
2024-09-21 10:15:00 +00:00
mining.address = lib.mkOption {
type = lib.types.str;
2018-02-05 21:02:14 +00:00
default = "";
description = ''
Monero address where to send mining rewards.
'';
};
2024-09-21 10:15:00 +00:00
mining.threads = lib.mkOption {
type = lib.types.addCheck lib.types.int (x: x>=0);
2018-02-05 21:02:14 +00:00
default = 0;
description = ''
Number of threads used for mining.
Set to `0` to use all available.
'';
};
2024-09-21 10:15:00 +00:00
rpc.user = lib.mkOption {
type = lib.types.nullOr lib.types.str;
2018-02-05 21:02:14 +00:00
default = null;
description = ''
User name for RPC connections.
'';
};
2024-09-21 10:15:00 +00:00
rpc.password = lib.mkOption {
type = lib.types.nullOr lib.types.str;
2018-02-05 21:02:14 +00:00
default = null;
description = ''
Password for RPC connections.
'';
};
2024-09-21 10:15:00 +00:00
rpc.address = lib.mkOption {
type = lib.types.str;
2018-02-05 21:02:14 +00:00
default = "127.0.0.1";
description = ''
IP address the RPC server will bind to.
'';
};
2024-09-21 10:15:00 +00:00
rpc.port = lib.mkOption {
type = lib.types.port;
2018-02-05 21:02:14 +00:00
default = 18081;
description = ''
Port the RPC server will bind to.
'';
};
2024-09-21 10:15:00 +00:00
rpc.restricted = lib.mkOption {
type = lib.types.bool;
2018-02-05 21:02:14 +00:00
default = false;
description = ''
Whether to restrict RPC to view only commands.
'';
};
2024-09-21 10:15:00 +00:00
limits.upload = lib.mkOption {
type = lib.types.addCheck lib.types.int (x: x>=-1);
2018-02-05 21:02:14 +00:00
default = -1;
description = ''
Limit of the upload rate in kB/s.
Set to `-1` to leave unlimited.
'';
};
2024-09-21 10:15:00 +00:00
limits.download = lib.mkOption {
type = lib.types.addCheck lib.types.int (x: x>=-1);
2018-02-05 21:02:14 +00:00
default = -1;
description = ''
Limit of the download rate in kB/s.
Set to `-1` to leave unlimited.
'';
};
2024-09-21 10:15:00 +00:00
limits.threads = lib.mkOption {
type = lib.types.addCheck lib.types.int (x: x>=0);
2018-02-05 21:02:14 +00:00
default = 0;
description = ''
Maximum number of threads used for a parallel job.
Set to `0` to leave unlimited.
'';
};
2024-09-21 10:15:00 +00:00
limits.syncSize = lib.mkOption {
type = lib.types.addCheck lib.types.int (x: x>=0);
2018-02-05 21:02:14 +00:00
default = 0;
description = ''
Maximum number of blocks to sync at once.
Set to `0` for adaptive.
'';
};
2024-09-21 10:15:00 +00:00
extraNodes = lib.mkOption {
type = lib.types.listOf lib.types.str;
2018-02-05 21:02:14 +00:00
default = [ ];
description = ''
List of additional peer IP addresses to add to the local list.
'';
};
2024-09-21 10:15:00 +00:00
priorityNodes = lib.mkOption {
type = lib.types.listOf lib.types.str;
2018-02-05 21:02:14 +00:00
default = [ ];
description = ''
List of peer IP addresses to connect to and
attempt to keep the connection open.
'';
};
2024-09-21 10:15:00 +00:00
exclusiveNodes = lib.mkOption {
type = lib.types.listOf lib.types.str;
2018-02-05 21:02:14 +00:00
default = [ ];
description = ''
List of peer IP addresses to connect to *only*.
If given the other peer options will be ignored.
'';
};
2024-09-21 10:15:00 +00:00
extraConfig = lib.mkOption {
type = lib.types.lines;
2018-02-05 21:02:14 +00:00
default = "";
description = ''
Extra lines to be added verbatim to monerod configuration.
'';
};
};
};
###### implementation
2024-09-21 10:15:00 +00:00
config = lib.mkIf cfg.enable {
2018-02-05 21:02:14 +00:00
users.users.monero = {
2021-05-05 12:47:46 +00:00
isSystemUser = true;
group = "monero";
2018-02-05 21:02:14 +00:00
description = "Monero daemon user";
2021-05-04 21:12:54 +00:00
home = cfg.dataDir;
2018-02-05 21:02:14 +00:00
createHome = true;
};
2021-05-05 12:47:46 +00:00
users.groups.monero = { };
2018-02-05 21:02:14 +00:00
systemd.services.monero = {
description = "monero daemon";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
User = "monero";
Group = "monero";
ExecStart = "${pkgs.monero-cli}/bin/monerod --config-file=${configFile} --non-interactive";
2018-02-05 21:02:14 +00:00
Restart = "always";
SuccessExitStatus = [ 0 1 ];
};
};
2024-09-21 10:15:00 +00:00
assertions = lib.singleton {
2019-12-04 16:07:45 +00:00
assertion = cfg.mining.enable -> cfg.mining.address != "";
message = ''
2018-02-05 21:02:14 +00:00
You need a Monero address to receive mining rewards:
specify one using option monero.mining.address.
2019-12-04 16:07:45 +00:00
'';
};
2018-02-05 21:02:14 +00:00
};
2019-12-04 16:07:45 +00:00
meta.maintainers = with lib.maintainers; [ rnhmjoj ];
2018-02-05 21:02:14 +00:00
}