2021-02-03 21:44:43 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
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;
|
2021-12-08 03:07:28 +00:00
|
|
|
defaultText = "config.nix-bitcoin.pkgs.lndconnect";
|
2021-02-03 21:44:43 +00:00
|
|
|
description = "The package providing lndconnect binaries.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-09-13 11:40:47 +00:00
|
|
|
cfg = config.services.lnd.restOnionService;
|
|
|
|
nbLib = config.nix-bitcoin.lib;
|
|
|
|
runAsUser = config.nix-bitcoin.runAsUserCmd;
|
|
|
|
|
|
|
|
lnd = config.services.lnd;
|
|
|
|
|
|
|
|
bin = pkgs.writeScriptBin "lndconnect-rest-onion" ''
|
|
|
|
#!/usr/bin/env -S ${runAsUser} ${lnd.user} ${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=${lnd.certPath} "$@"
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
inherit options;
|
|
|
|
|
2021-02-03 21:44:43 +00:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
services.tor = {
|
|
|
|
enable = true;
|
2021-08-04 22:49:00 +00:00
|
|
|
relay.onionServices.lnd-rest = nbLib.mkOnionService {
|
2021-10-01 09:51:57 +00:00
|
|
|
target.addr = nbLib.address lnd.restAddress;
|
2021-08-04 22:49:00 +00:00
|
|
|
target.port = lnd.restPort;
|
2021-02-03 21:44:43 +00:00
|
|
|
port = lnd.restPort;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
nix-bitcoin.onionAddresses.access.lnd = [ "lnd-rest" ];
|
|
|
|
|
|
|
|
environment.systemPackages = [ bin ];
|
|
|
|
};
|
|
|
|
}
|