diff --git a/README.md b/README.md index 077ee13..eeec067 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ Profiles * [lightning charge](https://github.com/ElementsProject/lightning-charge) * [nanopos](https://github.com/ElementsProject/nanopos) * adds an index page using nginx to display node information and link to nanopos + * [spark-wallet](https://github.com/shesek/spark-wallet) + * Notes: run `nodeinfo` to get its onion address and `systemctl status spark-wallet` to get the access key. + When entering the onion address on the Android app don't forgot to prepend "http://" The data directories can be found in `/var/lib`. diff --git a/configuration.nix b/configuration.nix index eb7ede3..3a362f0 100644 --- a/configuration.nix +++ b/configuration.nix @@ -8,6 +8,7 @@ let nodeinfo = (import pkgs/nodeinfo.nix); lightning-charge = import pkgs/lightning-charge.nix { inherit pkgs; }; nanopos = import pkgs/nanopos.nix { inherit pkgs; }; + spark-wallet = import pkgs/spark-wallet.nix { inherit pkgs; }; liquidd = import pkgs/liquidd.nix; in { imports = @@ -20,6 +21,7 @@ in { inherit nodeinfo; inherit lightning-charge; inherit nanopos; + inherit spark-wallet; liquidd = (pkgs.callPackage liquidd { }); }; services.nixbitcoin.enable = true; diff --git a/generate_secrets.sh b/generate_secrets.sh index 314abbb..cd6712a 100755 --- a/generate_secrets.sh +++ b/generate_secrets.sh @@ -15,6 +15,7 @@ echo Write secrets to $SECRETSFILE echo " bitcoinrpcpassword = \"$(apg -m 20 -x 20 -M Ncl -n 1)\";" echo " lightning-charge-api-token = \"$(apg -m 20 -x 20 -M Ncl -n 1)\";" echo " liquidrpcpassword = \"$(apg -m 20 -x 20 -M Ncl -n 1)\";" + echo " spark-wallet-password = \"$(apg -m 20 -x 20 -M Ncl -n 1)\";" echo \} } >> $SECRETSFILE echo Done diff --git a/modules/nixbitcoin.nix b/modules/nixbitcoin.nix index a952869..fdc15bb 100644 --- a/modules/nixbitcoin.nix +++ b/modules/nixbitcoin.nix @@ -15,6 +15,7 @@ let liquidd lightning-charge.package nanopos.package + spark-wallet.package nodejs-8_x nginx ]; @@ -27,6 +28,7 @@ in { ./nanopos.nix ./nixbitcoin-webindex.nix ./liquid.nix + ./spark-wallet.nix ]; options.services.nixbitcoin = { @@ -125,6 +127,13 @@ in { services.nanopos.enable = cfg.modules == "all"; services.nixbitcoin-webindex.enable = cfg.modules == "all"; services.clightning.autolisten = cfg.modules == "all"; + services.spark-wallet.enable = cfg.modules == "all"; + services.tor.hiddenServices.spark-wallet = { + map = [{ + port = 80; toPort = 9737; + }]; + version = 3; + }; environment.systemPackages = if (cfg.modules == "all") then (minimalPackages ++ allPackages) else minimalPackages; }; } diff --git a/modules/spark-wallet.nix b/modules/spark-wallet.nix new file mode 100644 index 0000000..0cde120 --- /dev/null +++ b/modules/spark-wallet.nix @@ -0,0 +1,44 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.spark-wallet; +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."; + ''; + }; + }; + + config = mkIf cfg.enable { + systemd.services.spark-wallet = + { description = "Run spark-wallet"; + wantedBy = [ "multi-user.target" ]; + requires = [ "clightning.service" ]; + after = [ "clightning.service" ]; + serviceConfig = + { + ExecStart = "${pkgs.spark-wallet.package}/bin/spark-wallet --ln-path ${cfg.ln-path} -k -c /secrets/spark-wallet-password"; + User = "clightning"; + Restart = "on-failure"; + RestartSec = "10s"; + PrivateTmp = "true"; + ProtectSystem = "full"; + NoNewPrivileges = "true"; + PrivateDevices = "true"; + }; + }; + }; +} diff --git a/network.nix b/network.nix index c6b59d7..61bf492 100644 --- a/network.nix +++ b/network.nix @@ -29,6 +29,13 @@ let group = "liquid"; permissions = "0440"; }; + spark-wallet-login = { + text = "login=" + "spark-wallet:" + secrets.spark-wallet-password; + destDir = "/secrets/"; + user = "clightning"; + group = "clightning"; + permissions = "0440"; + }; in { network.description = "Bitcoin Core node"; @@ -41,6 +48,7 @@ in { inherit bitcoin-rpcpassword lightning-charge-api-token; } // (if (config.services.nanopos.enable) then { inherit lightning-charge-api-token-for-nanopos; } else { }) - // (if (config.services.liquidd.enable) then { inherit liquid-rpcpassword; } else { }); + // (if (config.services.liquidd.enable) then { inherit liquid-rpcpassword; } else { }) + // (if (config.services.spark-wallet.enable) then { inherit spark-wallet-login; } else { }); } // (bitcoin-node { inherit config pkgs; }); } diff --git a/pkgs/nodeinfo.sh b/pkgs/nodeinfo.sh index 4dfd115..0d4a47b 100644 --- a/pkgs/nodeinfo.sh +++ b/pkgs/nodeinfo.sh @@ -16,3 +16,15 @@ if [ -e "$NGINX_ONION_FILE" ]; then NGINX_ONION="$(cat $NGINX_ONION_FILE)" echo NGINX_ONION="$NGINX_ONION" fi + +NGINX_ONION_FILE=/var/lib/tor/onion/nginx/hostname +if [ -e "$NGINX_ONION_FILE" ]; then + NGINX_ONION="$(cat $NGINX_ONION_FILE)" + echo NGINX_ONION="$NGINX_ONION" +fi + +SPARKWALLET_ONION_FILE=/var/lib/tor/onion/spark-wallet/hostname +if [ -e "$SPARKWALLET_ONION_FILE" ]; then + SPARKWALLET_ONION="$(cat $SPARKWALLET_ONION_FILE)" + echo SPARKWALLET_ONION="http://$SPARKWALLET_ONION" +fi diff --git a/pkgs/spark-wallet.nix b/pkgs/spark-wallet.nix new file mode 100644 index 0000000..9f20ebf --- /dev/null +++ b/pkgs/spark-wallet.nix @@ -0,0 +1,33 @@ +{pkgs ? import { + inherit system; + }, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-8_x"}: + + +with pkgs; +let + d1 = stdenv.mkDerivation { + name = "spark-wallet-sources"; + src = fetchurl { + url = "https://registry.npmjs.org/spark-wallet/-/spark-wallet-0.2.0-rc.3.tgz"; + sha256 = "991855f6c103c3e2abfd6421597db31948bc3fb967d9066f0d804a88c22390fd"; + }; + + buildInputs = [ nodePackages.node2nix git ]; + + unpackPhase = '' + mkdir -p $out + tar -xzf $src -C $out + ''; + + installPhase = '' + mkdir -p $out + cd $out/package + ${nodePackages.node2nix}/bin/node2nix -8 package.json + ''; + }; + # import from derivation (IFD) + packages = import (d1 + "/package/default.nix") { + inherit pkgs system; + }; +in +packages