From 127b186c3cd9df03f6408940ba2dbd4d5001e93c Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Fri, 16 Oct 2020 17:43:02 +0200 Subject: [PATCH] spark-wallet: simplify start script Also: - quote paths - use long form args --- modules/spark-wallet.nix | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/modules/spark-wallet.nix b/modules/spark-wallet.nix index cd2a860..1ef8d56 100644 --- a/modules/spark-wallet.nix +++ b/modules/spark-wallet.nix @@ -6,19 +6,21 @@ let cfg = config.services.spark-wallet; inherit (config) nix-bitcoin-services; onion-chef-service = (if cfg.onion-service then [ "onion-chef.service" ] else []); - run-spark-wallet = pkgs.writeScript "run-spark-wallet" '' - CMD="${pkgs.nix-bitcoin.spark-wallet}/bin/spark-wallet --ln-path ${cfg.ln-path} --host ${cfg.host} -Q -k -c ${config.nix-bitcoin.secretsDir}/spark-wallet-login ${cfg.extraArgs}" - ${optionalString cfg.onion-service - '' - echo Getting onion hostname - CMD="$CMD --public-url http://$(cat /var/lib/onion-chef/spark-wallet/spark-wallet)" - '' - } - # 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}" - echo Running $CMD - $CMD + + # 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 \ + --ln-path '${cfg.ln-path}' \ + --host ${cfg.host} \ + --config '${config.nix-bitcoin.secretsDir}/spark-wallet-login' \ + ${torRateProvider} \ + $publicURL \ + --pairing-qr --print-key ${cfg.extraArgs} ''; in { options.services.spark-wallet = { @@ -84,8 +86,8 @@ in { wantedBy = [ "multi-user.target" ]; requires = [ "clightning.service" ] ++ onion-chef-service; after = [ "clightning.service" ] ++ onion-chef-service; + script = startScript; serviceConfig = nix-bitcoin-services.defaultHardening // { - ExecStart = "${pkgs.bash}/bin/bash ${run-spark-wallet}"; User = "spark-wallet"; Restart = "on-failure"; RestartSec = "10s";