2021-12-19 01:06:50 +00:00
|
|
|
{ config, lib, options, pkgs, ... }:
|
2020-06-15 15:56:04 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.wasabibackend;
|
2021-12-19 01:06:50 +00:00
|
|
|
opt = options.services.wasabibackend;
|
2020-06-15 15:56:04 +00:00
|
|
|
|
2021-12-19 01:06:50 +00:00
|
|
|
inherit (lib) literalExpression mkEnableOption mkIf mkOption optionalAttrs optionalString types;
|
2020-06-15 15:56:04 +00:00
|
|
|
|
|
|
|
confOptions = {
|
|
|
|
BitcoinRpcConnectionString = "${cfg.rpc.user}:${cfg.rpc.password}";
|
|
|
|
} // optionalAttrs (cfg.network == "mainnet") {
|
|
|
|
Network = "Main";
|
|
|
|
MainNetBitcoinP2pEndPoint = "${cfg.endpoint.ip}:${toString cfg.endpoint.port}";
|
|
|
|
MainNetBitcoinCoreRpcEndPoint = "${cfg.rpc.ip}:${toString cfg.rpc.port}";
|
|
|
|
} // optionalAttrs (cfg.network == "testnet") {
|
|
|
|
Network = "TestNet";
|
|
|
|
TestNetBitcoinP2pEndPoint = "${cfg.endpoint.ip}:${toString cfg.endpoint.port}";
|
|
|
|
TestNetBitcoinCoreRpcEndPoint = "${cfg.rpc.ip}:${toString cfg.rpc.port}";
|
|
|
|
} // optionalAttrs (cfg.network == "regtest") {
|
|
|
|
Network = "RegTest";
|
|
|
|
RegTestBitcoinP2pEndPoint = "${cfg.endpoint.ip}:${toString cfg.endpoint.port}";
|
|
|
|
RegTestBitcoinCoreRpcEndPoint = "${cfg.rpc.ip}:${toString cfg.rpc.port}";
|
|
|
|
};
|
|
|
|
|
2020-11-24 20:58:05 +00:00
|
|
|
configFile = pkgs.writeText "wasabibackend.conf" (builtins.toJSON confOptions);
|
2020-06-15 15:56:04 +00:00
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.wasabibackend = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "Wasabi backend service");
|
2020-06-15 15:56:04 +00:00
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/wasabibackend";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The data directory for the Wasabi backend node.";
|
2020-06-15 15:56:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
customConfigFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Defines the path to a custom configuration file that is copied to the user's directory. Overrides any config options.";
|
2020-06-15 15:56:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
network = mkOption {
|
|
|
|
type = types.enum [ "mainnet" "testnet" "regtest" ];
|
|
|
|
default = "mainnet";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The network to use for the Wasabi backend service.";
|
2020-06-15 15:56:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
endpoint = {
|
|
|
|
ip = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "IP address for P2P connection to bitcoind.";
|
2020-06-15 15:56:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8333;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Port for P2P connection to bitcoind.";
|
2020-06-15 15:56:04 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
rpc = {
|
|
|
|
ip = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "IP address for RPC connection to bitcoind.";
|
2020-06-15 15:56:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8332;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Port for RPC connection to bitcoind.";
|
2020-06-15 15:56:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "bitcoin";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "RPC user for the bitcoin endpoint.";
|
2020-06-15 15:56:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
password = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "password";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "RPC password for the bitcoin endpoint. Warning: this is stored in cleartext in the Nix store! Use `configFile` or `passwordFile` if needed.";
|
2020-06-15 15:56:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
passwordFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "File that contains the password of the RPC user.";
|
2020-06-15 15:56:04 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "wasabibackend";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The user as which to run the wasabibackend node.";
|
2020-06-15 15:56:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = cfg.user;
|
2021-12-19 01:06:50 +00:00
|
|
|
defaultText = literalExpression "config.${opt.user}";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The group as which to run the wasabibackend node.";
|
2020-06-15 15:56:04 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.dataDir}' 0770 '${cfg.user}' '${cfg.group}' - -"
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.wasabibackend = {
|
|
|
|
description = "wasabibackend server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
environment = {
|
|
|
|
DOTNET_PRINT_TELEMETRY_MESSAGE = "false";
|
|
|
|
DOTNET_CLI_TELEMETRY_OPTOUT = "true";
|
|
|
|
};
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p ${cfg.dataDir}/.walletwasabi/backend
|
|
|
|
${if cfg.customConfigFile != null then ''
|
|
|
|
cp -v ${cfg.customConfigFile} ${cfg.dataDir}/.walletwasabi/backend/Config.json
|
|
|
|
'' else ''
|
|
|
|
cp -v ${configFile} ${cfg.dataDir}/.walletwasabi/backend/Config.json
|
|
|
|
${optionalString (cfg.rpc.passwordFile != null) ''
|
|
|
|
CONFIGTMP=$(mktemp)
|
|
|
|
cat ${cfg.dataDir}/.walletwasabi/backend/Config.json | ${pkgs.jq}/bin/jq --arg rpconnection "${cfg.rpc.user}:$(cat "${cfg.rpc.passwordFile}")" '. + { BitcoinRpcConnectionString: $rpconnection }' > $CONFIGTMP
|
|
|
|
mv $CONFIGTMP ${cfg.dataDir}/.walletwasabi/backend/Config.json
|
|
|
|
''}
|
|
|
|
''}
|
|
|
|
chmod ug+w ${cfg.dataDir}/.walletwasabi/backend/Config.json
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
ExecStart = "${pkgs.wasabibackend}/bin/WasabiBackend";
|
|
|
|
ProtectSystem = "full";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.${cfg.user} = {
|
|
|
|
name = cfg.user;
|
|
|
|
group = cfg.group;
|
|
|
|
description = "wasabibackend daemon user";
|
|
|
|
home = cfg.dataDir;
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.${cfg.group} = {};
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|