2018-12-10 08:34:41 -08:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.spark-wallet;
|
2019-11-27 05:04:23 -08:00
|
|
|
inherit (config) nix-bitcoin-services;
|
2019-03-26 17:49:54 -07:00
|
|
|
dataDir = "/var/lib/spark-wallet/";
|
|
|
|
onion-chef-service = (if cfg.onion-service then [ "onion-chef.service" ] else []);
|
|
|
|
run-spark-wallet = pkgs.writeScript "run-spark-wallet" ''
|
2020-01-12 11:52:39 -08:00
|
|
|
CMD="${pkgs.nix-bitcoin.spark-wallet}/bin/spark-wallet --ln-path ${cfg.ln-path} -Q -k -c ${config.nix-bitcoin.secretsDir}/spark-wallet-login"
|
2019-03-26 17:49:54 -07:00
|
|
|
${optionalString cfg.onion-service
|
|
|
|
''
|
|
|
|
echo Getting onion hostname
|
2020-05-03 05:18:21 -07:00
|
|
|
CMD="$CMD --public-url http://$(cat /var/lib/onion-chef/spark-wallet/spark-wallet)"
|
2019-03-26 17:49:54 -07:00
|
|
|
''
|
|
|
|
}
|
2019-06-11 15:19:59 -07:00
|
|
|
# Use rate provide wasabi because default (bitstamp) doesn't accept
|
|
|
|
# connections through Tor and add proxy for rate lookup.
|
|
|
|
CMD="$CMD --rate-provider wasabi --proxy socks5h://${config.services.tor.client.socksListenAddress}"
|
2019-03-26 17:49:54 -07:00
|
|
|
echo Running $CMD
|
|
|
|
$CMD
|
|
|
|
'';
|
2018-12-10 08:34:41 -08:00
|
|
|
in {
|
|
|
|
options.services.spark-wallet = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If enabled, the spark-wallet service will be installed.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
ln-path = mkOption {
|
|
|
|
type = types.path;
|
2020-01-09 05:27:46 -08:00
|
|
|
default = "${config.services.clightning.dataDir}/bitcoin";
|
2018-12-10 08:34:41 -08:00
|
|
|
description = ''
|
2020-01-09 05:27:46 -08:00
|
|
|
"The path of the clightning network data directory.";
|
2018-12-10 08:34:41 -08:00
|
|
|
'';
|
|
|
|
};
|
2019-03-26 17:49:54 -07:00
|
|
|
onion-service = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
"If enabled, configures spark-wallet to be reachable through an onion service.";
|
|
|
|
'';
|
|
|
|
};
|
2018-12-10 08:34:41 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2020-04-07 13:47:45 -07:00
|
|
|
environment.systemPackages = [ pkgs.nix-bitcoin.spark-wallet ];
|
2020-05-03 05:18:21 -07:00
|
|
|
users.users.spark-wallet = {
|
|
|
|
description = "spark-wallet User";
|
|
|
|
group = "spark-wallet";
|
|
|
|
extraGroups = [ "clightning" ];
|
|
|
|
};
|
|
|
|
users.groups.spark-wallet = {};
|
|
|
|
|
2019-03-26 17:49:54 -07:00
|
|
|
services.tor.enable = cfg.onion-service;
|
2019-06-11 15:19:59 -07:00
|
|
|
# requires client functionality for Bitcoin rate lookup
|
|
|
|
services.tor.client.enable = true;
|
2019-03-26 17:49:54 -07:00
|
|
|
services.tor.hiddenServices.spark-wallet = mkIf cfg.onion-service {
|
|
|
|
map = [{
|
|
|
|
port = 80; toPort = 9737;
|
|
|
|
}];
|
|
|
|
version = 3;
|
|
|
|
};
|
|
|
|
services.onion-chef.enable = cfg.onion-service;
|
2020-05-03 05:18:21 -07:00
|
|
|
services.onion-chef.access.spark-wallet = if cfg.onion-service then [ "spark-wallet" ] else [];
|
2019-01-02 07:17:57 -08:00
|
|
|
systemd.services.spark-wallet = {
|
|
|
|
description = "Run spark-wallet";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2019-03-26 17:49:54 -07:00
|
|
|
requires = [ "clightning.service" ] ++ onion-chef-service;
|
|
|
|
after = [ "clightning.service" ] ++ onion-chef-service;
|
2019-01-02 07:17:57 -08:00
|
|
|
serviceConfig = {
|
2019-03-26 17:49:54 -07:00
|
|
|
PermissionsStartOnly = "true";
|
|
|
|
ExecStart = "${pkgs.bash}/bin/bash ${run-spark-wallet}";
|
2020-05-03 05:18:21 -07:00
|
|
|
User = "spark-wallet";
|
2019-01-02 07:17:57 -08:00
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
2019-04-27 16:53:26 -07:00
|
|
|
} // nix-bitcoin-services.defaultHardening
|
2019-05-03 03:44:16 -07:00
|
|
|
// nix-bitcoin-services.nodejs
|
2019-04-27 16:53:26 -07:00
|
|
|
// nix-bitcoin-services.allowTor;
|
2018-12-10 08:34:41 -08:00
|
|
|
};
|
2020-05-03 05:18:21 -07:00
|
|
|
nix-bitcoin.secrets.spark-wallet-login.user = "spark-wallet";
|
2019-01-02 07:17:57 -08:00
|
|
|
};
|
2018-12-10 08:34:41 -08:00
|
|
|
}
|