2018-12-10 16:34:41 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.spark-wallet;
|
2019-11-27 13:04:23 +00:00
|
|
|
inherit (config) nix-bitcoin-services;
|
2019-03-27 00:49:54 +00:00
|
|
|
onion-chef-service = (if cfg.onion-service then [ "onion-chef.service" ] else []);
|
2020-10-16 15:43:02 +00: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 = ''
|
|
|
|
${optionalString cfg.onion-service ''
|
|
|
|
publicURL="--public-url http://$(cat /var/lib/onion-chef/spark-wallet/spark-wallet)"
|
|
|
|
''}
|
|
|
|
exec ${pkgs.nix-bitcoin.spark-wallet}/bin/spark-wallet \
|
2020-10-16 15:43:04 +00:00
|
|
|
--ln-path '${config.services.clightning.networkDir}' \
|
2020-10-16 15:43:02 +00:00
|
|
|
--host ${cfg.host} \
|
|
|
|
--config '${config.nix-bitcoin.secretsDir}/spark-wallet-login' \
|
2020-10-16 15:43:03 +00:00
|
|
|
${optionalString cfg.enforceTor torRateProvider} \
|
2020-10-16 15:43:02 +00:00
|
|
|
$publicURL \
|
|
|
|
--pairing-qr --print-key ${cfg.extraArgs}
|
2019-03-27 00:49:54 +00:00
|
|
|
'';
|
2018-12-10 16:34:41 +00:00
|
|
|
in {
|
|
|
|
options.services.spark-wallet = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If enabled, the spark-wallet service will be installed.
|
|
|
|
'';
|
|
|
|
};
|
2020-06-10 14:41:13 +00:00
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
|
|
|
description = "http(s) server listen address.";
|
|
|
|
};
|
2019-03-27 00:49:54 +00:00
|
|
|
onion-service = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
"If enabled, configures spark-wallet to be reachable through an onion service.";
|
|
|
|
'';
|
|
|
|
};
|
2020-06-10 14:41:13 +00:00
|
|
|
extraArgs = mkOption {
|
|
|
|
type = types.separatedString " ";
|
|
|
|
default = "";
|
|
|
|
description = "Extra command line arguments passed to spark-wallet.";
|
|
|
|
};
|
|
|
|
enforceTor = nix-bitcoin-services.enforceTor;
|
2018-12-10 16:34:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2020-10-18 12:49:20 +00:00
|
|
|
services.clightning.enable = true;
|
2020-06-15 10:34:11 +00:00
|
|
|
|
2020-05-03 12:18:21 +00:00
|
|
|
users.users.spark-wallet = {
|
|
|
|
description = "spark-wallet User";
|
|
|
|
group = "spark-wallet";
|
|
|
|
extraGroups = [ "clightning" ];
|
|
|
|
};
|
|
|
|
users.groups.spark-wallet = {};
|
|
|
|
|
2019-03-27 00:49:54 +00:00
|
|
|
services.tor.hiddenServices.spark-wallet = mkIf cfg.onion-service {
|
|
|
|
map = [{
|
2020-06-10 14:41:13 +00:00
|
|
|
port = 80; toPort = 9737; toHost = cfg.host;
|
2019-03-27 00:49:54 +00:00
|
|
|
}];
|
|
|
|
version = 3;
|
|
|
|
};
|
|
|
|
services.onion-chef.enable = cfg.onion-service;
|
2020-05-03 12:18:21 +00:00
|
|
|
services.onion-chef.access.spark-wallet = if cfg.onion-service then [ "spark-wallet" ] else [];
|
2019-01-02 15:17:57 +00:00
|
|
|
systemd.services.spark-wallet = {
|
|
|
|
description = "Run spark-wallet";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2019-03-27 00:49:54 +00:00
|
|
|
requires = [ "clightning.service" ] ++ onion-chef-service;
|
|
|
|
after = [ "clightning.service" ] ++ onion-chef-service;
|
2020-10-16 15:43:02 +00:00
|
|
|
script = startScript;
|
2020-05-05 13:18:41 +00:00
|
|
|
serviceConfig = nix-bitcoin-services.defaultHardening // {
|
2020-05-03 12:18:21 +00:00
|
|
|
User = "spark-wallet";
|
2019-01-02 15:17:57 +00:00
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
2020-09-28 11:09:06 +00:00
|
|
|
ReadWritePaths = mkIf cfg.onion-service "/var/lib/onion-chef";
|
2020-06-10 14:41:13 +00:00
|
|
|
} // (if cfg.enforceTor
|
|
|
|
then nix-bitcoin-services.allowTor
|
|
|
|
else nix-bitcoin-services.allowAnyIP)
|
|
|
|
// nix-bitcoin-services.nodejs;
|
2018-12-10 16:34:41 +00:00
|
|
|
};
|
2020-05-03 12:18:21 +00:00
|
|
|
nix-bitcoin.secrets.spark-wallet-login.user = "spark-wallet";
|
2019-01-02 15:17:57 +00:00
|
|
|
};
|
2018-12-10 16:34:41 +00:00
|
|
|
}
|