2018-12-10 08:34:41 -08:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.spark-wallet;
|
2021-02-03 13:44:41 -08:00
|
|
|
nbLib = config.nix-bitcoin.lib;
|
2020-10-16 08:43:02 -07:00
|
|
|
|
|
|
|
# Use wasabi rate provider because the default (bitstamp) doesn't accept
|
|
|
|
# connections through Tor
|
|
|
|
torRateProvider = "--rate-provider wasabi --proxy socks5h://${config.services.tor.client.socksListenAddress}";
|
|
|
|
startScript = ''
|
2021-01-14 04:24:19 -08:00
|
|
|
${optionalString (cfg.getPublicAddressCmd != "") ''
|
|
|
|
publicURL="--public-url http://$(${cfg.getPublicAddressCmd})"
|
2020-10-16 08:43:02 -07:00
|
|
|
''}
|
2020-11-09 13:09:09 -08:00
|
|
|
exec ${config.nix-bitcoin.pkgs.spark-wallet}/bin/spark-wallet \
|
2020-10-16 08:43:04 -07:00
|
|
|
--ln-path '${config.services.clightning.networkDir}' \
|
2021-01-14 04:24:08 -08:00
|
|
|
--host ${cfg.address} --port ${toString cfg.port} \
|
2020-10-16 08:43:02 -07:00
|
|
|
--config '${config.nix-bitcoin.secretsDir}/spark-wallet-login' \
|
2020-10-16 08:43:03 -07:00
|
|
|
${optionalString cfg.enforceTor torRateProvider} \
|
2020-10-16 08:43:02 -07:00
|
|
|
$publicURL \
|
|
|
|
--pairing-qr --print-key ${cfg.extraArgs}
|
2019-03-26 17:49:54 -07:00
|
|
|
'';
|
2018-12-10 08:34:41 -08:00
|
|
|
in {
|
|
|
|
options.services.spark-wallet = {
|
2021-02-01 13:53:15 -08:00
|
|
|
enable = mkEnableOption "spark-wallet";
|
2021-01-14 04:24:08 -08:00
|
|
|
address = mkOption {
|
2020-06-10 07:41:13 -07:00
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
2021-01-14 04:24:08 -08:00
|
|
|
description = "http(s) server address.";
|
|
|
|
};
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 9737;
|
|
|
|
description = "http(s) server port.";
|
2020-06-10 07:41:13 -07:00
|
|
|
};
|
|
|
|
extraArgs = mkOption {
|
|
|
|
type = types.separatedString " ";
|
|
|
|
default = "";
|
|
|
|
description = "Extra command line arguments passed to spark-wallet.";
|
|
|
|
};
|
2021-01-14 04:24:19 -08:00
|
|
|
getPublicAddressCmd = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Bash expression which outputs the public service address.
|
|
|
|
If set, spark-wallet prints a QR code to the systemd journal which
|
|
|
|
encodes an URL for accessing the web interface.
|
|
|
|
'';
|
|
|
|
};
|
2021-02-16 08:51:15 -08:00
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "spark-wallet";
|
|
|
|
description = "The user as which to run spark-wallet.";
|
|
|
|
};
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = cfg.user;
|
|
|
|
description = "The group as which to run spark-wallet.";
|
|
|
|
};
|
2021-02-03 13:44:41 -08:00
|
|
|
inherit (nbLib) enforceTor;
|
2018-12-10 08:34:41 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2020-10-18 05:49:20 -07:00
|
|
|
services.clightning.enable = true;
|
2020-06-15 03:34:11 -07:00
|
|
|
|
2021-02-16 08:51:15 -08:00
|
|
|
users.users.${cfg.user} = {
|
|
|
|
group = cfg.group;
|
|
|
|
extraGroups = [ config.services.clightning.group ];
|
2020-05-03 05:18:21 -07:00
|
|
|
};
|
2021-02-16 08:51:15 -08:00
|
|
|
users.groups.${cfg.group} = {};
|
2020-05-03 05:18:21 -07:00
|
|
|
|
2019-01-02 07:17:57 -08:00
|
|
|
systemd.services.spark-wallet = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-01-14 04:24:19 -08:00
|
|
|
requires = [ "clightning.service" ];
|
|
|
|
after = [ "clightning.service" ];
|
2020-10-16 08:43:02 -07:00
|
|
|
script = startScript;
|
2021-02-03 13:44:41 -08:00
|
|
|
serviceConfig = nbLib.defaultHardening // {
|
2021-02-16 08:51:15 -08:00
|
|
|
User = cfg.user;
|
2019-01-02 07:17:57 -08:00
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
2021-03-22 05:19:45 -07:00
|
|
|
} // nbLib.allowedIPAddresses cfg.enforceTor
|
2021-02-03 13:44:41 -08:00
|
|
|
// nbLib.nodejs;
|
2018-12-10 08:34:41 -08:00
|
|
|
};
|
2021-02-16 08:51:15 -08:00
|
|
|
nix-bitcoin.secrets.spark-wallet-login.user = cfg.user;
|
2019-01-02 07:17:57 -08:00
|
|
|
};
|
2018-12-10 08:34:41 -08:00
|
|
|
}
|