From 52810e6c88a5b172dded71d3085637e3671b416d Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Sat, 11 Mar 2023 18:59:47 +0100 Subject: [PATCH] nodeinfo/lnd: add `onion_rest_address` --- modules/lndconnect.nix | 5 ++++- modules/nodeinfo.nix | 15 +++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/modules/lndconnect.nix b/modules/lndconnect.nix index 6bfb5d2..bc39ab8 100644 --- a/modules/lndconnect.nix +++ b/modules/lndconnect.nix @@ -162,7 +162,10 @@ in { port = lnd.restPort; }; }; - nix-bitcoin.onionAddresses.access.${lnd.user} = [ "lnd-rest" ]; + nix-bitcoin.onionAddresses.access = { + ${lnd.user} = [ "lnd-rest" ]; + ${operatorName} = [ "lnd-rest" ]; + }; }) ])) diff --git a/modules/nodeinfo.nix b/modules/nodeinfo.nix index 47f3e40..e5ab81d 100644 --- a/modules/nodeinfo.nix +++ b/modules/nodeinfo.nix @@ -63,7 +63,7 @@ let infos = OrderedDict() operator = "${config.nix-bitcoin.operator.name}" - def set_onion_address(info, name, port): + def get_onion_address(name, port): path = f"/var/lib/onion-addresses/{operator}/{name}" try: with open(path, "r") as f: @@ -71,7 +71,7 @@ let except OSError: print(f"error reading file {path}", file=sys.stderr) return - info["onion_address"] = f"{onion_address}:{port}" + return f"{onion_address}:{port}" def add_service(service, make_info, systemd_service = None): systemd_service = systemd_service or service @@ -106,7 +106,7 @@ let add_service("${name}", """ info["local_address"] = "${nbLib.addressWithPort cfg.address cfg.port}" '' + mkIfOnionPort name (onionPort: '' - set_onion_address(info, "${name}", ${onionPort}) + info["onion_address"] = get_onion_address("${name}", ${onionPort}) '') + extraCode + '' """, "${systemdServiceName}") @@ -133,10 +133,13 @@ in { if 'onion_address' in info: info["id"] = f"{info['nodeid']}@{info['onion_address']}" ''; - lnd = name: cfg: mkInfo '' + lnd = name: cfg: mkInfo ('' info["rest_address"] = "${nbLib.addressWithPort cfg.restAddress cfg.restPort}" + '' + mkIfOnionPort "lnd-rest" (onionPort: '' + info["onion_rest_address"] = get_onion_address("lnd-rest", ${onionPort}) + '') + '' info["nodeid"] = shell("lncli getinfo | jq -r '.identity_pubkey'") - '' name cfg; + '') name cfg; clightning-rest = mkInfo ""; electrs = mkInfo ""; fulcrum = mkInfo ""; @@ -147,7 +150,7 @@ in { rtl = mkInfo ""; # Only add sshd when it has an onion service sshd = name: cfg: mkIfOnionPort "sshd" (onionPort: '' - add_service("sshd", """set_onion_address(info, "sshd", ${onionPort})""") + add_service("sshd", """info["onion_address"] = get_onion_address("sshd", ${onionPort})""") ''); }; };