joinmarket-obwatcher: add pkg & module

This commit is contained in:
nixbitcoin 2021-01-17 12:24:57 +00:00
parent 915df059f4
commit 8c125ec48c
No known key found for this signature in database
GPG Key ID: DD11F9AD5308B3BA
11 changed files with 126 additions and 0 deletions

View File

@ -69,6 +69,7 @@ NixOS modules
* [liquid](https://github.com/elementsproject/elements) * [liquid](https://github.com/elementsproject/elements)
* [Lightning Loop](https://github.com/lightninglabs/loop) * [Lightning Loop](https://github.com/lightninglabs/loop)
* [JoinMarket](https://github.com/joinmarket-org/joinmarket-clientserver) * [JoinMarket](https://github.com/joinmarket-org/joinmarket-clientserver)
* [JoinMarket Orderbook Watcher](https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/master/docs/orderbook.md)
* [recurring-donations](modules/recurring-donations.nix): for periodic lightning payments * [recurring-donations](modules/recurring-donations.nix): for periodic lightning payments
* [bitcoin-core-hwi](https://github.com/bitcoin-core/HWI) * [bitcoin-core-hwi](https://github.com/bitcoin-core/HWI)
* Helper * Helper

View File

@ -179,6 +179,8 @@
# earn sats by providing CoinJoin liquidity. This makes it impossible to use other # earn sats by providing CoinJoin liquidity. This makes it impossible to use other
# scripts that access your wallet. # scripts that access your wallet.
# services.joinmarket.yieldgenerator.enable = true; # services.joinmarket.yieldgenerator.enable = true;
# Enable this option to enable the JoinMarket order book watcher.
# services.joinmarket-ob-watcher.enable = true;
# FIXME: Define your hostname. # FIXME: Define your hostname.
networking.hostName = "nix-bitcoin"; networking.hostName = "nix-bitcoin";

View File

@ -0,0 +1,99 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.joinmarket-ob-watcher;
inherit (config) nix-bitcoin-services;
nbPkgs = config.nix-bitcoin.pkgs;
torAddress = builtins.head (builtins.split ":" config.services.tor.client.socksListenAddress);
configFile = builtins.toFile "config" ''
[BLOCKCHAIN]
blockchain_source = no-blockchain
[MESSAGING:server1]
host = darksci3bfoka7tw.onion
channel = joinmarket-pit
port = 6697
usessl = true
socks5 = true
socks5_host = ${torAddress}
socks5_port = 9050
[MESSAGING:server2]
host = ncwkrwxpq2ikcngxq3dy2xctuheniggtqeibvgofixpzvrwpa77tozqd.onion
channel = joinmarket-pit
port = 6667
usessl = false
socks5 = true
socks5_host = ${torAddress}
socks5_port = 9050
'';
in {
options.services.joinmarket-ob-watcher = {
enable = mkEnableOption "JoinMarket orderbook watcher";
address = mkOption {
type = types.str;
default = "127.0.0.1";
description = "HTTP server address.";
};
port = mkOption {
type = types.port;
default = 62601;
description = "HTTP server port.";
};
dataDir = mkOption {
readOnly = true;
default = "/var/lib/joinmarket-ob-watcher";
description = "The data directory for JoinMarket orderbook watcher.";
};
user = mkOption {
type = types.str;
default = "joinmarket-ob-watcher";
description = "The user as which to run JoinMarket orderbook watcher.";
};
group = mkOption {
type = types.str;
default = cfg.user;
description = "The group as which to run JoinMarket orderbook watcher.";
};
# This option is only used by netns-isolation
enforceTor = mkOption {
readOnly = true;
default = true;
};
};
config = mkIf cfg.enable {
services.tor = {
enable = true;
client.enable = true;
};
systemd.services.joinmarket-ob-watcher = {
wantedBy = [ "multi-user.target" ];
requires = [ "tor.service" ];
after = [ "tor.service" ];
preStart = ''
ln -snf ${configFile} ${cfg.dataDir}/joinmarket.cfg
'';
serviceConfig = nix-bitcoin-services.defaultHardening // rec {
StateDirectory = "joinmarket-ob-watcher";
StateDirectoryMode = "0770";
WorkingDirectory = "${cfg.dataDir}"; # The service creates dir 'logs' in the working dir
ExecStart = ''
${nbPkgs.joinmarket}/bin/ob-watcher --datadir=${cfg.dataDir} \
--host=${cfg.address} --port=${toString cfg.port}
'';
User = cfg.user;
Restart = "on-failure";
RestartSec = "10s";
} // nix-bitcoin-services.allowTor;
};
users.users.${cfg.user} = {
group = cfg.group;
home = cfg.dataDir; # The service writes to HOME/.config/matplotlib
};
users.groups.${cfg.group} = {};
};
}

View File

@ -18,6 +18,7 @@ with lib;
./electrs.nix ./electrs.nix
./liquid.nix ./liquid.nix
./joinmarket.nix ./joinmarket.nix
./joinmarket-ob-watcher.nix
./hardware-wallets.nix ./hardware-wallets.nix
./recurring-donations.nix ./recurring-donations.nix

View File

@ -242,6 +242,9 @@ in {
id = 25; id = 25;
connections = [ "bitcoind" ]; connections = [ "bitcoind" ];
}; };
joinmarket-ob-watcher = {
id = 26;
};
}; };
services.bitcoind = { services.bitcoind = {
@ -285,6 +288,8 @@ in {
services.joinmarket.cliExec = mkCliExec "joinmarket"; services.joinmarket.cliExec = mkCliExec "joinmarket";
systemd.services.joinmarket-yieldgenerator.serviceConfig.NetworkNamespacePath = "/var/run/netns/nb-joinmarket"; systemd.services.joinmarket-yieldgenerator.serviceConfig.NetworkNamespacePath = "/var/run/netns/nb-joinmarket";
services.joinmarket-ob-watcher.address = netns.joinmarket-ob-watcher.address;
} }
]); ]);
} }

View File

@ -19,6 +19,7 @@ let
spark-wallet = mkInfo ""; spark-wallet = mkInfo "";
btcpayserver = mkInfo ""; btcpayserver = mkInfo "";
liquidd = mkInfo ""; liquidd = mkInfo "";
joinmarket-ob-watcher = mkInfo "";
# Only add sshd when it has an onion service # Only add sshd when it has an onion service
sshd = name: cfg: mkIfOnionPort "sshd" (onionPort: '' sshd = name: cfg: mkIfOnionPort "sshd" (onionPort: ''
add_service("sshd", """set_onion_address(info, "sshd", ${onionPort})""") add_service("sshd", """set_onion_address(info, "sshd", ${onionPort})""")

View File

@ -115,6 +115,9 @@ in {
btcpayserver = { btcpayserver = {
externalPort = 80; externalPort = 80;
}; };
joinmarket-ob-watcher = {
externalPort = 80;
};
}; };
} }
]; ];

View File

@ -28,5 +28,6 @@ in {
liquidd.enable = defaultTrue; liquidd.enable = defaultTrue;
electrs.enable = defaultTrue; electrs.enable = defaultTrue;
spark-wallet.enable = defaultTrue; spark-wallet.enable = defaultTrue;
joinmarket-ob-watcher.enable = defaultTrue;
}; };
} }

View File

@ -12,6 +12,7 @@ let
joinmarketclient joinmarketclient
joinmarketbitcoin joinmarketbitcoin
joinmarketdaemon joinmarketdaemon
matplotlib # for ob-watcher
]; ];
pythonEnv = python3.withPackages (_: runtimePackages); pythonEnv = python3.withPackages (_: runtimePackages);
@ -31,6 +32,7 @@ stdenv.mkDerivation {
} }
cp scripts/joinmarketd.py $out/bin/joinmarketd cp scripts/joinmarketd.py $out/bin/joinmarketd
cp scripts/obwatch/ob-watcher.py $out/bin/ob-watcher
cpBin add-utxo.py cpBin add-utxo.py
cpBin convert_old_wallet.py cpBin convert_old_wallet.py
cpBin receive-payjoin.py cpBin receive-payjoin.py
@ -43,5 +45,8 @@ stdenv.mkDerivation {
chmod +x -R $out/bin chmod +x -R $out/bin
patchShebangs $out/bin patchShebangs $out/bin
# This file must be placed in the same dir as ob-watcher
cp scripts/obwatch/orderbook.html $out/bin/orderbook.html
''; '';
} }

View File

@ -60,6 +60,7 @@ let testEnv = rec {
tests.joinmarket = cfg.joinmarket.enable; tests.joinmarket = cfg.joinmarket.enable;
tests.joinmarket-yieldgenerator = cfg.joinmarket.yieldgenerator.enable; tests.joinmarket-yieldgenerator = cfg.joinmarket.yieldgenerator.enable;
tests.joinmarket-ob-watcher = cfg.joinmarket-ob-watcher.enable;
services.joinmarket.yieldgenerator = { services.joinmarket.yieldgenerator = {
enable = config.services.joinmarket.enable; enable = config.services.joinmarket.enable;
customParameters = '' customParameters = ''
@ -119,6 +120,7 @@ let testEnv = rec {
services.liquidd.enable = true; services.liquidd.enable = true;
services.btcpayserver.enable = true; services.btcpayserver.enable = true;
services.joinmarket.enable = true; services.joinmarket.enable = true;
services.joinmarket-ob-watcher.enable = true;
services.backups.enable = true; services.backups.enable = true;
nix-bitcoin.nodeinfo.enable = true; nix-bitcoin.nodeinfo.enable = true;

View File

@ -216,6 +216,12 @@ def _():
) )
@test("joinmarket-ob-watcher")
def _():
assert_running("joinmarket-ob-watcher")
machine.wait_until_succeeds(log_has_string("joinmarket-ob-watcher", "Starting ob-watcher"))
@test("nodeinfo") @test("nodeinfo")
def _(): def _():
status, _ = machine.execute("systemctl is-enabled --quiet onion-addresses 2> /dev/null") status, _ = machine.execute("systemctl is-enabled --quiet onion-addresses 2> /dev/null")