2021-01-17 15:24:57 +03:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.joinmarket-ob-watcher;
|
2021-02-04 00:44:41 +03:00
|
|
|
nbLib = config.nix-bitcoin.lib;
|
2021-01-17 15:24:57 +03:00
|
|
|
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.";
|
|
|
|
};
|
|
|
|
# This option is only used by netns-isolation
|
|
|
|
enforceTor = mkOption {
|
|
|
|
readOnly = true;
|
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-02-02 00:53:22 +03:00
|
|
|
# Joinmarket is Tor-only
|
2021-01-17 15:24:57 +03:00
|
|
|
services.tor = {
|
|
|
|
enable = true;
|
|
|
|
client.enable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.joinmarket-ob-watcher = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "tor.service" ];
|
|
|
|
after = [ "tor.service" ];
|
2021-02-02 00:53:19 +03:00
|
|
|
# The service writes to HOME/.config/matplotlib
|
|
|
|
environment.HOME = cfg.dataDir;
|
2021-01-17 15:24:57 +03:00
|
|
|
preStart = ''
|
|
|
|
ln -snf ${configFile} ${cfg.dataDir}/joinmarket.cfg
|
|
|
|
'';
|
2021-02-04 00:44:41 +03:00
|
|
|
serviceConfig = nbLib.defaultHardening // rec {
|
2021-02-02 00:53:19 +03:00
|
|
|
DynamicUser = true;
|
2021-01-17 15:24:57 +03:00
|
|
|
StateDirectory = "joinmarket-ob-watcher";
|
|
|
|
StateDirectoryMode = "0770";
|
2021-02-02 00:53:12 +03:00
|
|
|
WorkingDirectory = cfg.dataDir; # The service creates dir 'logs' in the working dir
|
2021-01-17 15:24:57 +03:00
|
|
|
ExecStart = ''
|
|
|
|
${nbPkgs.joinmarket}/bin/ob-watcher --datadir=${cfg.dataDir} \
|
|
|
|
--host=${cfg.address} --port=${toString cfg.port}
|
|
|
|
'';
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
2021-02-04 00:44:41 +03:00
|
|
|
} // nbLib.allowTor;
|
2021-01-17 15:24:57 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|