···
+
{ config, lib, pkgs, ... }:
+
cfg = config.services.monero;
+
dataDir = "/var/lib/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" ''
+
${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 ''
+
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}
+
enable = mkEnableOption "Monero node daemon.";
+
mining.enable = mkOption {
+
Whether to mine moneroj.
+
mining.address = mkOption {
+
Monero address where to send mining rewards.
+
mining.threads = mkOption {
+
type = types.addCheck types.int (x: x>=0);
+
Number of threads used for mining.
+
Set to <literal>0</literal> to use all available.
+
type = types.nullOr types.str;
+
User name for RPC connections.
+
rpc.password = mkOption {
+
Password for RPC connections.
+
rpc.address = mkOption {
+
IP address the RPC server will bind to.
+
Port the RPC server will bind to.
+
rpc.restricted = mkOption {
+
Whether to restrict RPC to view only commands.
+
limits.upload = mkOption {
+
type = types.addCheck types.int (x: x>=-1);
+
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);
+
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);
+
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);
+
Maximum number of blocks to sync at once.
+
Set to <literal>0</literal> for adaptive.
+
extraNodes = mkOption {
+
type = types.listOf types.str;
+
List of additional peer IP addresses to add to the local list.
+
priorityNodes = mkOption {
+
type = types.listOf types.str;
+
List of peer IP addresses to connect to and
+
attempt to keep the connection open.
+
exclusiveNodes = mkOption {
+
type = types.listOf types.str;
+
List of peer IP addresses to connect to *only*.
+
If given the other peer options will be ignored.
+
extraConfig = mkOption {
+
Extra lines to be added verbatim to monerod configuration.
+
config = mkIf cfg.enable {
+
users.extraUsers = singleton {
+
uid = config.ids.uids.monero;
+
description = "Monero daemon user";
+
users.extraGroups = singleton {
+
gid = config.ids.gids.monero;
+
systemd.services.monero = {
+
description = "monero daemon";
+
after = [ "network.target" ];
+
wantedBy = [ "multi-user.target" ];
+
ExecStart = "${pkgs.monero}/bin/monerod --config-file=${configFile} --non-interactive";
+
SuccessExitStatus = [ 0 1 ];
+
assertions = singleton {
+
assertion = cfg.mining.enable -> cfg.mining.address != "";
+
You need a Monero address to receive mining rewards:
+
specify one using option monero.mining.address.