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

245 lines
5.7 KiB
Nix
Raw Normal View History

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