diff --git a/README.md b/README.md index e8817b5..ea801e4 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ NixOS modules * [summary](https://github.com/lightningd/plugins/tree/master/summary): print a nice summary of the node status * [zmq](https://github.com/lightningd/plugins/tree/master/zmq): publishes notifications via ZeroMQ to configured endpoints * [lnd](https://github.com/lightningnetwork/lnd) with support for announcing an onion service + * [lndconnect](https://github.com/LN-Zap/lndconnect) via a REST onion service * [spark-wallet](https://github.com/shesek/spark-wallet) * [electrs](https://github.com/romanz/electrs) * [btcpayserver](https://github.com/btcpayserver/btcpayserver) diff --git a/examples/configuration.nix b/examples/configuration.nix index 5d79067..7452eff 100644 --- a/examples/configuration.nix +++ b/examples/configuration.nix @@ -63,6 +63,12 @@ # The onion service is automatically announced to peers. # nix-bitcoin.onionServices.lnd.public = true; # + # Set this to create an lnd REST onion service. + # Adds binary `lndconnect-rest-onion` to the system environment. + # This binary generates QR codes or URIs for connecting applications to lnd via the + # REST onion service. + # services.lnd.restOnionService.enable = true; + # ## WARNING # If you use lnd, you should manually backup your wallet mnemonic # seed. This will allow you to recover on-chain funds. You can run the diff --git a/modules/lnd-rest-onion-service.nix b/modules/lnd-rest-onion-service.nix new file mode 100644 index 0000000..8e182f1 --- /dev/null +++ b/modules/lnd-rest-onion-service.nix @@ -0,0 +1,51 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.lnd.restOnionService; + nbLib = config.nix-bitcoin.lib; + secretsDir = config.nix-bitcoin.secretsDir; + + lnd = config.services.lnd; + + bin = pkgs.writeScriptBin "lndconnect-rest-onion" '' + #!/usr/bin/env -S sudo -u lnd ${pkgs.bash}/bin/bash + + exec ${cfg.package}/bin/lndconnect \ + --host=$(cat ${config.nix-bitcoin.onionAddresses.dataDir}/lnd/lnd-rest) \ + --port=${toString lnd.restPort} \ + --lnddir=${lnd.dataDir} \ + --tlscertpath=${secretsDir}/lnd-cert "$@" + ''; +in { + options.services.lnd.restOnionService = { + enable = mkOption { + default = false; + type = types.bool; + description = '' + Create an onion service for the lnd REST service. + Add a `lndconnect-rest-onion` binary (https://github.com/LN-Zap/lndconnect) to the system environment. + This binary generates QR codes or URIs for connecting applications to lnd via the REST onion service. + ''; + }; + package = mkOption { + type = types.package; + default = config.nix-bitcoin.pkgs.lndconnect; + description = "The package providing lndconnect binaries."; + }; + }; + + config = mkIf cfg.enable { + services.tor = { + enable = true; + hiddenServices.lnd-rest = nbLib.mkHiddenService { + toHost = lnd.restAddress; + port = lnd.restPort; + }; + }; + nix-bitcoin.onionAddresses.access.lnd = [ "lnd-rest" ]; + + environment.systemPackages = [ bin ]; + }; +} diff --git a/modules/modules.nix b/modules/modules.nix index 3372e30..548bc37 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -13,6 +13,7 @@ with lib; ./clightning-plugins ./spark-wallet.nix ./lnd.nix + ./lnd-rest-onion-service.nix ./lightning-loop.nix ./btcpayserver.nix ./electrs.nix diff --git a/pkgs/pinned.nix b/pkgs/pinned.nix index 00c99ef..a1086b0 100644 --- a/pkgs/pinned.nix +++ b/pkgs/pinned.nix @@ -11,6 +11,7 @@ in bitcoind clightning lnd + lndconnect nbxplorer btcpayserver; diff --git a/test/tests.nix b/test/tests.nix index b7ce86e..b99462c 100644 --- a/test/tests.nix +++ b/test/tests.nix @@ -46,6 +46,8 @@ let testEnv = rec { tests.lnd = cfg.lnd.enable; services.lnd.port = 9736; + tests.lnd-rest-onion-service = cfg.lnd.restOnionService.enable; + tests.lightning-loop = cfg.lightning-loop.enable; tests.electrs = cfg.electrs.enable; @@ -115,6 +117,7 @@ let testEnv = rec { test.features.clightningPlugins = true; services.spark-wallet.enable = true; services.lnd.enable = true; + services.lnd.restOnionService.enable = true; services.lightning-loop.enable = true; services.electrs.enable = true; services.liquidd.enable = true; diff --git a/test/tests.py b/test/tests.py index 598bbd9..7832433 100644 --- a/test/tests.py +++ b/test/tests.py @@ -162,6 +162,11 @@ def _(): assert_no_failure("lnd") +@test("lnd-rest-onion-service") +def _(): + assert_matches("runuser -u operator -- lndconnect-rest-onion -j", ".onion") + + @test("lightning-loop") def _(): assert_running("lightning-loop")