2021-01-17 12:24:57 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
2021-09-13 11:40:47 +00:00
|
|
|
options.services.joinmarket-ob-watcher = {
|
|
|
|
enable = mkEnableOption "JoinMarket orderbook watcher";
|
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
2022-12-18 12:13:47 +00:00
|
|
|
description = mdDoc "HTTP server address.";
|
2021-09-13 11:40:47 +00:00
|
|
|
};
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 62601;
|
2022-12-18 12:13:47 +00:00
|
|
|
description = mdDoc "HTTP server port.";
|
2021-09-13 11:40:47 +00:00
|
|
|
};
|
|
|
|
dataDir = mkOption {
|
|
|
|
readOnly = true;
|
|
|
|
default = "/var/lib/joinmarket-ob-watcher";
|
2022-12-18 12:13:47 +00:00
|
|
|
description = mdDoc "The data directory for JoinMarket orderbook watcher.";
|
2021-09-13 11:40:47 +00:00
|
|
|
};
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "joinmarket-ob-watcher";
|
2022-12-18 12:13:47 +00:00
|
|
|
description = mdDoc "The user as which to run JoinMarket.";
|
2021-09-13 11:40:47 +00:00
|
|
|
};
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = cfg.user;
|
2022-12-18 12:13:47 +00:00
|
|
|
description = mdDoc "The group as which to run JoinMarket.";
|
2021-09-13 11:40:47 +00:00
|
|
|
};
|
2021-11-28 20:24:49 +00:00
|
|
|
# This option is only used by netns-isolation.
|
|
|
|
# Tor is always enabled.
|
|
|
|
tor.enforce = nbLib.tor.enforce;
|
2021-09-13 11:40:47 +00:00
|
|
|
};
|
|
|
|
|
2021-01-17 12:24:57 +00:00
|
|
|
cfg = config.services.joinmarket-ob-watcher;
|
2021-02-03 21:44:41 +00:00
|
|
|
nbLib = config.nix-bitcoin.lib;
|
2021-01-17 12:24:57 +00:00
|
|
|
nbPkgs = config.nix-bitcoin.pkgs;
|
2021-08-25 09:57:09 +00:00
|
|
|
secretsDir = config.nix-bitcoin.secretsDir;
|
2021-08-04 22:49:00 +00:00
|
|
|
|
2021-10-13 12:44:36 +00:00
|
|
|
inherit (config.services) bitcoind joinmarket;
|
2021-08-04 22:49:00 +00:00
|
|
|
|
2021-01-17 12:24:57 +00:00
|
|
|
configFile = builtins.toFile "config" ''
|
|
|
|
[BLOCKCHAIN]
|
2021-08-25 09:57:09 +00:00
|
|
|
blockchain_source = bitcoin-rpc
|
|
|
|
network = ${bitcoind.network}
|
|
|
|
rpc_host = ${bitcoind.rpc.address}
|
|
|
|
rpc_port = ${toString bitcoind.rpc.port}
|
|
|
|
rpc_user = ${bitcoind.rpc.users.joinmarket-ob-watcher.name}
|
2021-01-17 12:24:57 +00:00
|
|
|
|
2022-05-27 09:06:14 +00:00
|
|
|
${joinmarket.messagingConfig}
|
2021-01-17 12:24:57 +00:00
|
|
|
'';
|
|
|
|
in {
|
2021-09-13 11:40:47 +00:00
|
|
|
inherit options;
|
2021-01-17 12:24:57 +00:00
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-08-25 09:57:09 +00:00
|
|
|
services.bitcoind.rpc.users.joinmarket-ob-watcher = {
|
|
|
|
passwordHMACFromFile = true;
|
|
|
|
rpcwhitelist = bitcoind.rpc.users.public.rpcwhitelist ++ [
|
|
|
|
"listwallets"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2021-02-01 21:53:22 +00:00
|
|
|
# Joinmarket is Tor-only
|
2021-01-17 12:24:57 +00:00
|
|
|
services.tor = {
|
|
|
|
enable = true;
|
|
|
|
client.enable = true;
|
|
|
|
};
|
|
|
|
|
2021-08-25 09:57:09 +00:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -"
|
|
|
|
];
|
|
|
|
|
2021-10-06 09:27:47 +00:00
|
|
|
systemd.services.joinmarket-ob-watcher = rec {
|
2021-01-17 12:24:57 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-10-06 09:27:47 +00:00
|
|
|
requires = [ "tor.service" "bitcoind.service" ];
|
2023-10-03 11:00:23 +00:00
|
|
|
after = requires ++ [ "nix-bitcoin-secrets.target" ];
|
2021-02-01 21:53:19 +00:00
|
|
|
# The service writes to HOME/.config/matplotlib
|
|
|
|
environment.HOME = cfg.dataDir;
|
2021-01-17 12:24:57 +00:00
|
|
|
preStart = ''
|
2021-08-25 09:57:09 +00:00
|
|
|
{
|
|
|
|
cat ${configFile}
|
|
|
|
echo
|
|
|
|
echo '[BLOCKCHAIN]'
|
|
|
|
echo "rpc_password = $(cat ${secretsDir}/bitcoin-rpcpassword-joinmarket-ob-watcher)"
|
|
|
|
} > '${cfg.dataDir}/joinmarket.cfg'
|
2021-01-17 12:24:57 +00:00
|
|
|
'';
|
2021-02-03 21:44:41 +00:00
|
|
|
serviceConfig = nbLib.defaultHardening // rec {
|
2021-01-17 12:24:57 +00:00
|
|
|
StateDirectory = "joinmarket-ob-watcher";
|
2021-08-15 09:28:37 +00:00
|
|
|
StateDirectoryMode = "770";
|
2021-02-01 21:53:12 +00:00
|
|
|
WorkingDirectory = cfg.dataDir; # The service creates dir 'logs' in the working dir
|
2021-08-25 09:57:09 +00:00
|
|
|
User = cfg.user;
|
2021-01-17 12:24:57 +00:00
|
|
|
ExecStart = ''
|
2021-08-12 13:29:19 +00:00
|
|
|
${nbPkgs.joinmarket}/bin/jm-ob-watcher --datadir=${cfg.dataDir} \
|
2021-01-17 12:24:57 +00:00
|
|
|
--host=${cfg.address} --port=${toString cfg.port}
|
|
|
|
'';
|
2021-08-04 22:49:05 +00:00
|
|
|
SystemCallFilter = nbLib.defaultHardening.SystemCallFilter ++ [ "mbind" ] ;
|
2021-01-17 12:24:57 +00:00
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
2021-11-28 20:24:49 +00:00
|
|
|
} // nbLib.allowedIPAddresses cfg.tor.enforce;
|
2021-01-17 12:24:57 +00:00
|
|
|
};
|
2021-08-25 09:57:09 +00:00
|
|
|
|
|
|
|
users.users.${cfg.user} = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = cfg.group;
|
|
|
|
home = cfg.dataDir;
|
|
|
|
};
|
|
|
|
users.groups.${cfg.group} = {};
|
|
|
|
|
|
|
|
nix-bitcoin.secrets = {
|
|
|
|
bitcoin-rpcpassword-joinmarket-ob-watcher.user = cfg.user;
|
|
|
|
bitcoin-HMAC-joinmarket-ob-watcher.user = bitcoind.user;
|
|
|
|
};
|
2021-09-08 15:01:18 +00:00
|
|
|
nix-bitcoin.generateSecretsCmds.joinmarket-ob-watcher = ''
|
|
|
|
makeBitcoinRPCPassword joinmarket-ob-watcher
|
|
|
|
'';
|
2021-01-17 12:24:57 +00:00
|
|
|
};
|
|
|
|
}
|