2018-12-10 19:34:41 +03:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2019-04-28 02:53:26 +03:00
|
|
|
nix-bitcoin-services = pkgs.callPackage ./nix-bitcoin-services.nix { };
|
2018-12-10 19:34:41 +03:00
|
|
|
cfg = config.services.spark-wallet;
|
2019-03-27 03:49:54 +03: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" ''
|
|
|
|
CMD="${pkgs.spark-wallet}/bin/spark-wallet --ln-path ${cfg.ln-path} -Q -k -c /secrets/spark-wallet-login"
|
|
|
|
${optionalString cfg.onion-service
|
|
|
|
''
|
|
|
|
echo Getting onion hostname
|
|
|
|
CMD="$CMD --public-url http://$(cat /var/lib/onion-chef/clightning/spark-wallet)"
|
|
|
|
''
|
|
|
|
}
|
|
|
|
echo Running $CMD
|
|
|
|
$CMD
|
|
|
|
'';
|
2018-12-10 19:34:41 +03: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;
|
|
|
|
default = "/var/lib/clightning";
|
|
|
|
description = ''
|
|
|
|
"The path of the clightning data directory.";
|
|
|
|
'';
|
|
|
|
};
|
2019-03-27 03:49:54 +03: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 19:34:41 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2019-03-27 03:49:54 +03:00
|
|
|
services.tor.enable = cfg.onion-service;
|
|
|
|
services.tor.hiddenServices.spark-wallet = mkIf cfg.onion-service {
|
|
|
|
map = [{
|
|
|
|
port = 80; toPort = 9737;
|
|
|
|
}];
|
|
|
|
version = 3;
|
|
|
|
};
|
|
|
|
services.onion-chef.enable = cfg.onion-service;
|
|
|
|
services.onion-chef.access.clightning = if cfg.onion-service then [ "spark-wallet" ] else [];
|
2019-01-02 18:17:57 +03:00
|
|
|
systemd.services.spark-wallet = {
|
|
|
|
description = "Run spark-wallet";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2019-03-27 03:49:54 +03:00
|
|
|
requires = [ "clightning.service" ] ++ onion-chef-service;
|
|
|
|
after = [ "clightning.service" ] ++ onion-chef-service;
|
2019-01-02 18:17:57 +03:00
|
|
|
serviceConfig = {
|
2019-03-27 03:49:54 +03:00
|
|
|
PermissionsStartOnly = "true";
|
|
|
|
ExecStart = "${pkgs.bash}/bin/bash ${run-spark-wallet}";
|
2019-01-02 18:17:57 +03:00
|
|
|
User = "clightning";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
2019-04-28 02:53:26 +03:00
|
|
|
} // nix-bitcoin-services.defaultHardening
|
|
|
|
// nix-bitcoin-services.node
|
|
|
|
// nix-bitcoin-services.allowTor;
|
2018-12-10 19:34:41 +03:00
|
|
|
};
|
2019-01-02 18:17:57 +03:00
|
|
|
};
|
2018-12-10 19:34:41 +03:00
|
|
|
}
|