2020-04-23 19:18:47 +03:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
2021-09-13 14:40:47 +03:00
|
|
|
options.services.joinmarket = {
|
2021-12-14 21:51:23 +03:00
|
|
|
enable = mkEnableOption "JoinMarket, a Bitcoin CoinJoin implementation";
|
2021-10-24 22:14:09 +03:00
|
|
|
payjoinAddress = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc ''
|
2021-10-24 22:14:09 +03:00
|
|
|
The address where payjoin onion connections are forwarded to.
|
|
|
|
This address is never used directly, it only serves as the internal endpoint
|
|
|
|
for the payjoin onion service.
|
|
|
|
The onion service is automatically setup by joinmarket and accepts
|
|
|
|
connections at port 80.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
payjoinPort = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 64180; # A random private port
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc "The port corresponding to option {option}`payjoinAddress`.";
|
2021-10-24 22:14:09 +03:00
|
|
|
};
|
2022-05-27 12:06:14 +03:00
|
|
|
messagingAddress = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc ''
|
2022-05-27 12:06:14 +03:00
|
|
|
The address where messaging onion connections are forwarded to.
|
|
|
|
This address is never used directly, it only serves as the internal endpoint
|
|
|
|
for the messaging onion service.
|
|
|
|
The onion service is automatically setup by joinmarket.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
messagingPort = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 64181; # payjoinPort + 1
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc "The port corresponding to option {option}`messagingAddress`.";
|
2022-05-27 12:06:14 +03:00
|
|
|
};
|
2021-09-13 14:40:47 +03:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/joinmarket";
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc "The data directory for JoinMarket.";
|
2021-09-13 14:40:47 +03:00
|
|
|
};
|
2021-09-13 14:40:48 +03:00
|
|
|
rpcWalletFile = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = "jm_wallet";
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc ''
|
2021-09-13 14:40:48 +03:00
|
|
|
Name of the watch-only bitcoind wallet the JoinMarket addresses are imported to.
|
|
|
|
'';
|
|
|
|
};
|
2021-09-13 14:40:47 +03:00
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "joinmarket";
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc "The user as which to run JoinMarket.";
|
2021-09-13 14:40:47 +03:00
|
|
|
};
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = cfg.user;
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc "The group as which to run JoinMarket.";
|
2021-09-13 14:40:47 +03:00
|
|
|
};
|
|
|
|
cli = mkOption {
|
|
|
|
default = cli;
|
2021-12-08 06:07:27 +03:00
|
|
|
defaultText = "(See source)";
|
2021-09-13 14:40:47 +03:00
|
|
|
};
|
2021-10-13 15:44:36 +03:00
|
|
|
# Used by ./joinmarket-ob-watcher.nix
|
2022-05-27 12:06:14 +03:00
|
|
|
messagingConfig = mkOption {
|
2021-10-13 15:44:36 +03:00
|
|
|
readOnly = true;
|
2022-05-27 12:06:14 +03:00
|
|
|
default = messagingConfig;
|
2021-12-08 06:07:27 +03:00
|
|
|
defaultText = "(See source)";
|
2021-10-13 15:44:36 +03:00
|
|
|
};
|
2021-11-28 23:24:49 +03:00
|
|
|
# This option is only used by netns-isolation.
|
|
|
|
# Tor is always enabled.
|
|
|
|
tor.enforce = nbLib.tor.enforce;
|
2021-09-13 14:40:47 +03:00
|
|
|
inherit (nbLib) cliExec;
|
|
|
|
|
|
|
|
yieldgenerator = {
|
2021-12-14 21:51:23 +03:00
|
|
|
enable = mkEnableOption "JoinMarket yield generator bot";
|
2021-09-13 14:40:47 +03:00
|
|
|
ordertype = mkOption {
|
|
|
|
type = types.enum [ "reloffer" "absoffer" ];
|
|
|
|
default = "reloffer";
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc ''
|
|
|
|
Which fee type to actually use.
|
2021-09-13 14:40:47 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
cjfee_a = mkOption {
|
|
|
|
type = types.ints.unsigned;
|
|
|
|
default = 500;
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc ''
|
|
|
|
Absolute offer fee you wish to receive for coinjoins (cj) in Satoshis.
|
2021-09-13 14:40:47 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
cjfee_r = mkOption {
|
|
|
|
type = types.float;
|
|
|
|
default = 0.00002;
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc ''
|
|
|
|
Relative offer fee you wish to receive based on a cj's amount.
|
2021-09-13 14:40:47 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
cjfee_factor = mkOption {
|
|
|
|
type = types.float;
|
|
|
|
default = 0.1;
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc ''
|
|
|
|
Variance around the average cj fee.
|
2021-09-13 14:40:47 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
txfee = mkOption {
|
|
|
|
type = types.ints.unsigned;
|
|
|
|
default = 100;
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc ''
|
|
|
|
The average transaction fee you're adding to coinjoin transactions.
|
2021-09-13 14:40:47 +03:00
|
|
|
'';
|
|
|
|
};
|
2021-10-24 22:14:09 +03:00
|
|
|
txfee_contribution_factor = mkOption {
|
2021-09-13 14:40:47 +03:00
|
|
|
type = types.float;
|
|
|
|
default = 0.3;
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc ''
|
|
|
|
Variance around the average tx fee.
|
2021-09-13 14:40:47 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
minsize = mkOption {
|
|
|
|
type = types.ints.unsigned;
|
|
|
|
default = 100000;
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc ''
|
2021-09-13 14:40:47 +03:00
|
|
|
Minimum size of your cj offer in Satoshis. Lower cj amounts will be disregarded.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
size_factor = mkOption {
|
|
|
|
type = types.float;
|
|
|
|
default = 0.1;
|
2022-12-18 15:13:47 +03:00
|
|
|
description = mdDoc ''
|
|
|
|
Variance around all offer sizes.
|
2021-09-13 14:40:47 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-23 19:18:47 +03:00
|
|
|
cfg = config.services.joinmarket;
|
2021-02-04 00:44:41 +03:00
|
|
|
nbLib = config.nix-bitcoin.lib;
|
2020-11-10 00:09:09 +03:00
|
|
|
nbPkgs = config.nix-bitcoin.pkgs;
|
2020-04-23 19:18:47 +03:00
|
|
|
secretsDir = config.nix-bitcoin.secretsDir;
|
2021-01-31 01:08:43 +03:00
|
|
|
runAsUser = config.nix-bitcoin.runAsUserCmd;
|
2020-04-23 19:18:47 +03:00
|
|
|
|
2020-10-16 18:43:13 +03:00
|
|
|
inherit (config.services) bitcoind;
|
2021-08-05 01:49:00 +03:00
|
|
|
|
|
|
|
torAddress = config.services.tor.client.socksListenAddress;
|
|
|
|
socks5Settings = ''
|
|
|
|
socks5 = true
|
|
|
|
socks5_host = ${torAddress.addr}
|
|
|
|
socks5_port = ${toString torAddress.port}
|
|
|
|
'';
|
|
|
|
|
2022-05-27 12:06:14 +03:00
|
|
|
messagingConfig = ''
|
|
|
|
[MESSAGING:onion]
|
|
|
|
type = onion
|
|
|
|
${socks5Settings}
|
|
|
|
tor_control_host = unix:/run/tor/control
|
|
|
|
# required option, but ignored for unix socket host
|
|
|
|
tor_control_port = 9051
|
|
|
|
onion_serving_host = ${cfg.messagingAddress}
|
|
|
|
onion_serving_port = ${toString cfg.messagingPort}
|
|
|
|
hidden_service_dir =
|
2023-05-07 16:55:30 +03:00
|
|
|
directory_nodes = g3hv4uynnmynqqq2mchf3fcm3yd46kfzmcdogejuckgwknwyq5ya6iad.onion:5222,3kxw6lf5vf6y26emzwgibzhrzhmhqiw6ekrek3nqfjjmhwznb2moonad.onion:5222,bqlpq6ak24mwvuixixitift4yu42nxchlilrcqwk2ugn45tdclg42qid.onion:5222
|
2022-05-27 12:06:14 +03:00
|
|
|
|
2021-10-13 15:44:36 +03:00
|
|
|
# irc.darkscience.net
|
|
|
|
[MESSAGING:server1]
|
|
|
|
host = darkirc6tqgpnwd3blln3yfv5ckl47eg7llfxkmtovrv7c7iwohhb6ad.onion
|
|
|
|
channel = joinmarket-pit
|
|
|
|
port = 6697
|
|
|
|
usessl = true
|
|
|
|
${socks5Settings}
|
|
|
|
|
2022-05-27 12:06:14 +03:00
|
|
|
# ilita
|
2021-10-13 15:44:36 +03:00
|
|
|
[MESSAGING:server2]
|
2022-05-27 12:06:14 +03:00
|
|
|
host = ilitafrzzgxymv6umx2ux7kbz3imyeko6cnqkvy4nisjjj4qpqkrptid.onion
|
2021-10-13 15:44:36 +03:00
|
|
|
channel = joinmarket-pit
|
|
|
|
port = 6667
|
|
|
|
usessl = false
|
|
|
|
${socks5Settings}
|
2021-10-13 15:45:52 +03:00
|
|
|
|
2022-05-27 12:06:14 +03:00
|
|
|
# irc.hackint.org
|
2022-02-22 16:49:19 +03:00
|
|
|
[MESSAGING:server3]
|
2022-05-27 12:06:14 +03:00
|
|
|
host = ncwkrwxpq2ikcngxq3dy2xctuheniggtqeibvgofixpzvrwpa77tozqd.onion
|
2021-12-08 15:16:14 +03:00
|
|
|
channel = joinmarket-pit
|
|
|
|
port = 6667
|
|
|
|
usessl = false
|
|
|
|
${socks5Settings}
|
2021-10-13 15:44:36 +03:00
|
|
|
'';
|
|
|
|
|
2020-10-16 18:43:14 +03:00
|
|
|
# Based on https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/master/jmclient/jmclient/configure.py
|
2021-02-10 17:02:05 +03:00
|
|
|
yg = cfg.yieldgenerator;
|
2020-04-23 19:18:47 +03:00
|
|
|
configFile = builtins.toFile "config" ''
|
|
|
|
[DAEMON]
|
|
|
|
no_daemon = 0
|
|
|
|
daemon_port = 27183
|
2023-07-29 19:58:55 +03:00
|
|
|
daemon_host = 127.0.0.1
|
2020-04-23 19:18:47 +03:00
|
|
|
use_ssl = false
|
|
|
|
|
|
|
|
[BLOCKCHAIN]
|
2021-10-25 16:30:53 +03:00
|
|
|
blockchain_source = ${bitcoind.makeNetworkName "bitcoin-rpc" "regtest"}
|
|
|
|
network = ${bitcoind.makeNetworkName "mainnet" "testnet"}
|
2021-10-01 12:51:57 +03:00
|
|
|
rpc_host = ${nbLib.address bitcoind.rpc.address}
|
2020-10-16 18:43:15 +03:00
|
|
|
rpc_port = ${toString bitcoind.rpc.port}
|
2020-10-16 18:43:13 +03:00
|
|
|
rpc_user = ${bitcoind.rpc.users.privileged.name}
|
2021-08-08 11:58:49 +03:00
|
|
|
${optionalString (cfg.rpcWalletFile != null) "rpc_wallet_file = ${cfg.rpcWalletFile}"}
|
2020-04-23 19:18:47 +03:00
|
|
|
|
2022-05-27 12:06:14 +03:00
|
|
|
${messagingConfig}
|
2020-04-23 19:18:47 +03:00
|
|
|
|
|
|
|
[LOGGING]
|
|
|
|
console_log_level = INFO
|
|
|
|
color = false
|
|
|
|
|
|
|
|
[POLICY]
|
|
|
|
segwit = true
|
2020-12-14 20:12:11 +03:00
|
|
|
native = true
|
2020-04-23 19:18:47 +03:00
|
|
|
merge_algorithm = default
|
2023-11-11 20:40:49 +03:00
|
|
|
gaplimit = 6
|
2020-04-23 19:18:47 +03:00
|
|
|
tx_fees = 3
|
2021-10-24 22:14:09 +03:00
|
|
|
tx_fees_factor = 0.2
|
2020-04-23 19:18:47 +03:00
|
|
|
absurd_fee_per_kb = 350000
|
2021-02-10 17:02:05 +03:00
|
|
|
max_sweep_fee_change = 0.8
|
2020-04-23 19:18:47 +03:00
|
|
|
tx_broadcast = self
|
|
|
|
minimum_makers = 4
|
|
|
|
max_sats_freeze_reuse = -1
|
2022-01-11 14:05:42 +03:00
|
|
|
interest_rate = 0.015
|
|
|
|
bondless_makers_allowance = 0.125
|
2022-05-27 12:06:14 +03:00
|
|
|
bond_value_exponent = 1.3
|
2020-04-23 19:18:47 +03:00
|
|
|
taker_utxo_retries = 3
|
|
|
|
taker_utxo_age = 5
|
|
|
|
taker_utxo_amtpercent = 20
|
|
|
|
accept_commitment_broadcasts = 1
|
|
|
|
commit_file_location = cmtdata/commitments.json
|
2022-05-27 12:06:14 +03:00
|
|
|
commitment_list_location = cmtdata/commitmentlist
|
2020-10-29 15:46:36 +03:00
|
|
|
|
|
|
|
[PAYJOIN]
|
|
|
|
payjoin_version = 1
|
|
|
|
disable_output_substitution = 0
|
|
|
|
max_additional_fee_contribution = default
|
|
|
|
min_fee_rate = 1.1
|
2021-08-05 01:49:00 +03:00
|
|
|
onion_socks5_host = ${torAddress.addr}
|
|
|
|
onion_socks5_port = ${toString torAddress.port}
|
2020-10-29 15:46:36 +03:00
|
|
|
tor_control_host = unix:/run/tor/control
|
2022-05-27 12:06:14 +03:00
|
|
|
# Required option, but unused because `tor_control_host` is a Unix socket
|
|
|
|
tor_control_port = 9051
|
2021-10-24 22:14:09 +03:00
|
|
|
onion_serving_host = ${cfg.payjoinAddress}
|
|
|
|
onion_serving_port = ${toString cfg.payjoinPort}
|
2020-10-29 15:46:36 +03:00
|
|
|
hidden_service_ssl = false
|
2021-02-10 17:02:05 +03:00
|
|
|
|
|
|
|
[YIELDGENERATOR]
|
|
|
|
ordertype = ${yg.ordertype}
|
|
|
|
cjfee_a = ${toString yg.cjfee_a}
|
|
|
|
cjfee_r = ${toString yg.cjfee_r}
|
|
|
|
cjfee_factor = ${toString yg.cjfee_factor}
|
2021-10-24 22:14:09 +03:00
|
|
|
txfee_contribution = 0
|
|
|
|
txfee_contribution_factor = ${toString yg.txfee_contribution_factor}
|
2021-02-10 17:02:05 +03:00
|
|
|
minsize = ${toString yg.minsize}
|
|
|
|
size_factor = ${toString yg.size_factor}
|
2021-03-09 19:48:25 +03:00
|
|
|
|
|
|
|
[SNICKER]
|
|
|
|
enabled = false
|
|
|
|
lowest_net_gain = 0
|
|
|
|
servers = cn5lfwvrswicuxn3gjsxoved6l2gu5hdvwy5l3ev7kg6j7lbji2k7hqd.onion,
|
|
|
|
polling_interval_minutes = 60
|
2020-04-23 19:18:47 +03:00
|
|
|
'';
|
|
|
|
|
|
|
|
# The jm scripts create a 'logs' dir in the working dir,
|
|
|
|
# so run them inside dataDir.
|
|
|
|
cli = pkgs.runCommand "joinmarket-cli" {} ''
|
2022-08-01 00:32:12 +03:00
|
|
|
mkdir -p "$out/bin"
|
2020-11-10 00:09:09 +03:00
|
|
|
jm=${nbPkgs.joinmarket}/bin
|
2022-08-01 00:32:12 +03:00
|
|
|
cd "$jm"
|
2020-04-23 19:18:47 +03:00
|
|
|
for bin in jm-*; do
|
|
|
|
{
|
|
|
|
echo "#!${pkgs.bash}/bin/bash";
|
2022-08-01 00:32:12 +03:00
|
|
|
echo "cd '${cfg.dataDir}' && ${cfg.cliExec} ${runAsUser} ${cfg.user} "$jm/$bin" --datadir='${cfg.dataDir}' \"\$@\"";
|
|
|
|
} > "$out/bin/$bin"
|
2020-04-23 19:18:47 +03:00
|
|
|
done
|
2022-08-01 00:32:12 +03:00
|
|
|
chmod -R +x "$out/bin"
|
2020-04-23 19:18:47 +03:00
|
|
|
'';
|
|
|
|
in {
|
2021-09-13 14:40:47 +03:00
|
|
|
inherit options;
|
2020-04-23 19:18:47 +03:00
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [{
|
2021-02-02 00:53:22 +03:00
|
|
|
services.bitcoind = {
|
|
|
|
enable = true;
|
|
|
|
disablewallet = false;
|
2024-01-01 14:56:56 +03:00
|
|
|
# TODO-EXTERNAL: remove when joinmarket supports descriptor wallets
|
|
|
|
# (https://github.com/JoinMarket-Org/joinmarket-clientserver/issues/1571).
|
|
|
|
extraConfig = ''
|
|
|
|
deprecatedrpc=create_bdb
|
|
|
|
'';
|
2020-09-28 14:09:03 +03:00
|
|
|
};
|
2020-04-23 19:18:47 +03:00
|
|
|
|
2021-02-02 00:53:22 +03:00
|
|
|
# Joinmarket is Tor-only
|
2020-04-23 19:18:47 +03:00
|
|
|
services.tor = {
|
|
|
|
enable = true;
|
|
|
|
client.enable = true;
|
2021-02-02 00:53:18 +03:00
|
|
|
# Needed for payjoin onion service creation
|
2020-10-29 15:46:36 +03:00
|
|
|
controlSocket.enable = true;
|
2020-04-23 19:18:47 +03:00
|
|
|
};
|
|
|
|
|
2021-02-02 00:53:22 +03:00
|
|
|
environment.systemPackages = [
|
|
|
|
(hiPrio cfg.cli)
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -"
|
|
|
|
];
|
|
|
|
|
2020-04-23 19:18:47 +03:00
|
|
|
systemd.services.joinmarket = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "bitcoind.service" ];
|
2023-10-03 14:00:23 +03:00
|
|
|
after = [ "bitcoind.service" "nix-bitcoin-secrets.target" ];
|
2021-08-08 11:58:52 +03:00
|
|
|
preStart = ''
|
2021-08-27 18:09:11 +03:00
|
|
|
{
|
|
|
|
cat ${configFile}
|
|
|
|
echo
|
|
|
|
echo '[BLOCKCHAIN]'
|
|
|
|
echo "rpc_password = $(cat ${secretsDir}/bitcoin-rpcpassword-privileged)"
|
|
|
|
} > '${cfg.dataDir}/joinmarket.cfg'
|
|
|
|
'';
|
2021-10-25 16:30:53 +03:00
|
|
|
postStart = ''
|
2021-08-08 11:58:52 +03:00
|
|
|
walletname=wallet.jmdat
|
2022-08-01 00:32:12 +03:00
|
|
|
wallet="${cfg.dataDir}/wallets/$walletname"
|
2021-08-08 11:58:52 +03:00
|
|
|
if [[ ! -f $wallet ]]; then
|
|
|
|
${optionalString (cfg.rpcWalletFile != null) ''
|
|
|
|
echo "Create watch-only wallet ${cfg.rpcWalletFile}"
|
2021-08-27 15:37:44 +03:00
|
|
|
if ! output=$(${bitcoind.cli}/bin/bitcoin-cli -named createwallet \
|
2021-10-25 16:30:53 +03:00
|
|
|
wallet_name="${cfg.rpcWalletFile}" \
|
2022-05-05 15:50:19 +03:00
|
|
|
descriptors=false \
|
2021-10-25 16:30:53 +03:00
|
|
|
${optionalString (!bitcoind.regtest) "disable_private_keys=true"} 2>&1
|
|
|
|
); then
|
2021-08-27 15:37:44 +03:00
|
|
|
# Ignore error if bitcoind wallet already exists
|
|
|
|
if [[ $output != *"already exists"* ]]; then
|
|
|
|
echo "$output"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2021-08-08 11:58:52 +03:00
|
|
|
''}
|
2022-08-01 00:32:12 +03:00
|
|
|
|
2021-08-27 15:37:44 +03:00
|
|
|
# Restore wallet from seed if available
|
2022-08-01 00:32:12 +03:00
|
|
|
seed=()
|
2021-08-27 15:37:44 +03:00
|
|
|
if [[ -e jm-wallet-seed ]]; then
|
2022-08-01 00:32:12 +03:00
|
|
|
seed=(--recovery-seed-file jm-wallet-seed)
|
2021-08-27 15:37:44 +03:00
|
|
|
fi
|
2022-08-01 00:32:12 +03:00
|
|
|
cd "${cfg.dataDir}"
|
|
|
|
|
2021-08-27 18:09:11 +03:00
|
|
|
# Strip trailing newline from password file
|
2022-08-01 00:32:12 +03:00
|
|
|
if ! tr -d '\n' < '${secretsDir}/jm-wallet-password' \
|
2021-08-27 18:09:11 +03:00
|
|
|
| ${nbPkgs.joinmarket}/bin/jm-genwallet \
|
2022-08-01 00:32:12 +03:00
|
|
|
--datadir="${cfg.dataDir}" --wallet-password-stdin "''${seed[@]}" "$walletname" \
|
|
|
|
| (if ((! ''${#seed[@]})); then
|
2021-08-27 15:37:44 +03:00
|
|
|
umask u=r,go=
|
|
|
|
grep -ohP '(?<=recovery_seed:).*' > jm-wallet-seed
|
|
|
|
else
|
|
|
|
cat > /dev/null
|
|
|
|
fi); then
|
2021-08-08 11:58:52 +03:00
|
|
|
echo "wallet creation failed"
|
|
|
|
rm -f "$wallet" jm-wallet-seed
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
serviceConfig = nbLib.defaultHardening // {
|
2020-11-10 00:09:09 +03:00
|
|
|
ExecStart = "${nbPkgs.joinmarket}/bin/joinmarketd";
|
2021-02-02 00:53:12 +03:00
|
|
|
WorkingDirectory = cfg.dataDir; # The service creates 'commitmentlist' in the working dir
|
|
|
|
User = cfg.user;
|
2020-04-23 19:18:47 +03:00
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
2022-05-07 21:34:21 +03:00
|
|
|
ReadWritePaths = [ cfg.dataDir ];
|
2021-11-28 23:24:49 +03:00
|
|
|
} // nbLib.allowedIPAddresses cfg.tor.enforce;
|
2020-04-23 19:18:47 +03:00
|
|
|
};
|
|
|
|
|
2021-02-02 00:53:22 +03:00
|
|
|
users.users.${cfg.user} = {
|
2021-08-05 01:48:59 +03:00
|
|
|
isSystemUser = true;
|
2021-02-02 00:53:22 +03:00
|
|
|
group = cfg.group;
|
|
|
|
home = cfg.dataDir;
|
|
|
|
# Allow access to the tor control socket, needed for payjoin onion service creation
|
2021-08-08 11:58:48 +03:00
|
|
|
extraGroups = [ "tor" "bitcoin" ];
|
2021-02-02 00:53:22 +03:00
|
|
|
};
|
|
|
|
users.groups.${cfg.group} = {};
|
|
|
|
nix-bitcoin.operator = {
|
|
|
|
groups = [ cfg.group ];
|
2021-08-15 12:28:38 +03:00
|
|
|
allowRunAsUsers = [ cfg.user ];
|
2021-02-02 00:53:22 +03:00
|
|
|
};
|
|
|
|
|
2020-04-23 19:18:47 +03:00
|
|
|
nix-bitcoin.secrets.jm-wallet-password.user = cfg.user;
|
2021-09-08 18:01:18 +03:00
|
|
|
nix-bitcoin.generateSecretsCmds.joinmarket = ''
|
|
|
|
makePasswordSecret jm-wallet-password
|
|
|
|
'';
|
2020-12-30 18:02:42 +03:00
|
|
|
}
|
2020-04-23 19:18:47 +03:00
|
|
|
|
2020-12-30 18:02:42 +03:00
|
|
|
(mkIf cfg.yieldgenerator.enable {
|
2021-02-10 17:02:05 +03:00
|
|
|
systemd.services.joinmarket-yieldgenerator = {
|
2020-04-23 19:18:47 +03:00
|
|
|
wantedBy = [ "joinmarket.service" ];
|
|
|
|
requires = [ "joinmarket.service" ];
|
2023-10-03 14:00:23 +03:00
|
|
|
after = [ "joinmarket.service" "nix-bitcoin-secrets.target" ];
|
2021-08-27 18:06:17 +03:00
|
|
|
script = ''
|
|
|
|
tr -d "\n" <"${secretsDir}/jm-wallet-password" \
|
|
|
|
| ${nbPkgs.joinmarket}/bin/jm-yg-privacyenhanced --datadir='${cfg.dataDir}' \
|
|
|
|
--wallet-password-stdin wallet.jmdat
|
2020-04-23 19:18:47 +03:00
|
|
|
'';
|
2021-02-04 00:44:41 +03:00
|
|
|
serviceConfig = nbLib.defaultHardening // rec {
|
2021-02-02 00:53:12 +03:00
|
|
|
WorkingDirectory = cfg.dataDir; # The service creates dir 'logs' in the working dir
|
2021-02-02 00:53:20 +03:00
|
|
|
# Show "joinmarket-yieldgenerator" instead of "bash" in the journal.
|
2021-08-27 18:06:17 +03:00
|
|
|
# The start script has to run alongside the main process
|
2021-02-02 00:53:20 +03:00
|
|
|
# because it provides the wallet password via stdin to the main process
|
|
|
|
SyslogIdentifier = "joinmarket-yieldgenerator";
|
2021-02-02 00:53:12 +03:00
|
|
|
User = cfg.user;
|
2022-05-07 21:34:21 +03:00
|
|
|
ReadWritePaths = [ cfg.dataDir ];
|
2021-02-04 00:44:41 +03:00
|
|
|
} // nbLib.allowTor;
|
2020-04-23 19:18:47 +03:00
|
|
|
};
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|