Skip to content

Commit 915114c

Browse files
committed
lndhub-go: integrate LndHub.go
1 parent 81bf18b commit 915114c

File tree

10 files changed

+159
-1
lines changed

10 files changed

+159
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ NixOS modules ([src](modules/modules.nix))
8787
* [Lightning Pool](https://github.com/lightninglabs/pool)
8888
* [charge-lnd](https://github.com/accumulator/charge-lnd): policy-based channel fee manager
8989
* [lndconnect](https://github.com/LN-Zap/lndconnect): connect your wallet to lnd or clightning via a REST onion service
90+
* [LndHub.go](https://github.com/getAlby/lndhub.go): accounting wrapper for the Lightning Network
9091
* [Ride The Lightning](https://github.com/Ride-The-Lightning/RTL): web interface for `lnd` and `clightning`
9192
* [spark-wallet](https://github.com/shesek/spark-wallet)
9293
* [electrs](https://github.com/romanz/electrs)

examples/configuration.nix

+5
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@
136136
#
137137
# services.fulcrum.enable = true;
138138

139+
### LNDHUB.GO
140+
# Set this to enable LndHub.go, an accounting wrapper for the Lightning Network.
141+
#
142+
# services.lndhub-go.enable = true;
143+
139144
### BTCPayServer
140145
# Set this to enable BTCPayServer, a self-hosted, open-source
141146
# cryptocurrency payment processor.

modules/lndhub-go.nix

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
{ config, lib, pkgs, ... }:
2+
3+
with lib;
4+
let
5+
options.services = {
6+
lndhub-go = {
7+
enable = mkEnableOption "LndHub.go, an accounting wrapper for the Lightning Network";
8+
address = mkOption {
9+
type = types.str;
10+
default = "127.0.0.1";
11+
description = "Address to listen on.";
12+
};
13+
port = mkOption {
14+
type = types.port;
15+
default = 8082;
16+
description = "Port to listen on.";
17+
};
18+
settings = mkOption {
19+
type = with types; attrsOf (oneOf [ str int bool ]);
20+
example = {
21+
ALLOW_ACCOUNT_CREATION = false;
22+
FEE_RESERVE = true;
23+
MAX_SEND_AMOUNT = 1000000;
24+
};
25+
description = ''
26+
LndHub.go settings.
27+
See here for possible options:
28+
https://github.com/getAlby/lndhub.go#available-configuration
29+
'';
30+
};
31+
package = mkOption {
32+
type = types.package;
33+
default = config.nix-bitcoin.pkgs.lndhub-go;
34+
defaultText = "config.nix-bitcoin.pkgs.lndhub-go";
35+
description = "The package providing LndHub.go binaries.";
36+
};
37+
user = mkOption {
38+
type = types.str;
39+
default = "lndhub-go";
40+
description = "The user as which to run LndHub.go.";
41+
};
42+
group = mkOption {
43+
type = types.str;
44+
default = cfg.user;
45+
description = "The group as which to run LndHub.go.";
46+
};
47+
tor.enforce = nbLib.tor.enforce;
48+
};
49+
};
50+
51+
cfg = config.services.lndhub-go;
52+
nbLib = config.nix-bitcoin.lib;
53+
54+
inherit (config.services)
55+
lnd
56+
postgresql;
57+
58+
configFile = builtins.toFile "lndhub-go-conf" (lib.generators.toKeyValue {} cfg.settings);
59+
60+
dbName = "lndhub-go";
61+
in {
62+
inherit options;
63+
64+
config = mkIf cfg.enable {
65+
services.lnd = {
66+
enable = true;
67+
macaroons.lndhub-go = {
68+
inherit (cfg) user;
69+
permissions = ''{"entity":"info","action":"read"},{"entity":"invoices","action":"read"},{"entity":"invoices","action":"write"},{"entity":"offchain","action":"read"},{"entity":"offchain","action":"write"}'';
70+
};
71+
};
72+
services.postgresql = {
73+
enable = true;
74+
ensureDatabases = [ dbName ];
75+
ensureUsers = [
76+
{
77+
name = cfg.user;
78+
ensurePermissions."DATABASE \"${dbName}\"" = "ALL PRIVILEGES";
79+
}
80+
];
81+
};
82+
83+
services.lndhub-go.settings = {
84+
HOST = cfg.address;
85+
PORT = cfg.port;
86+
DATABASE_URI = "unix://${cfg.user}@${dbName}/run/postgresql/.s.PGSQL.${toString postgresql.port}?sslmode=disable";
87+
LND_ADDRESS = "${nbLib.addressWithPort lnd.address lnd.rpcPort}";
88+
LND_MACAROON_FILE = "/run/lnd/lndhub-go.macaroon";
89+
LND_CERT_FILE = lnd.certPath;
90+
BRANDING_TITLE = "LndHub.go - Nix-Bitcoin";
91+
BRANDING_DESC = "Accounting wrapper for the Lightning Network";
92+
BRANDING_URL = "https://nixbitcoin.org";
93+
BRANDING_LOGO = "https://nixbitcoin.org/files/nix-bitcoin-logo-text.png";
94+
BRANDING_FAVICON = "https://nixbitcoin.org/files/nix-bitcoin-logo.png";
95+
BRANDING_FOOTER = "about=https://nixbitcoin.org;github=https://github.com/fort-nix/nix-bitcoin";
96+
};
97+
98+
systemd.services.lndhub-go = rec {
99+
wantedBy = [ "multi-user.target" ];
100+
requires = [ "lnd.service" "postgresql.service" ];
101+
after = requires;
102+
preStart = ''
103+
{
104+
cat ${configFile}
105+
echo "JWT_SECRET=$(cat '${config.nix-bitcoin.secretsDir}/lndhub.go-jwt-secret')"
106+
} > .env
107+
'';
108+
serviceConfig = nbLib.defaultHardening // {
109+
StateDirectory = "lndhub-go";
110+
StateDirectoryMode = "770";
111+
# lndhub-go reads file `.env` from the working directory
112+
WorkingDirectory = "/var/lib/lndhub-go";
113+
ExecStart = "${config.nix-bitcoin.pkgs.lndhub-go}/bin/lndhub.go";
114+
User = cfg.user;
115+
Restart = "on-failure";
116+
RestartSec = "10s";
117+
} // nbLib.allowedIPAddresses cfg.tor.enforce;
118+
};
119+
120+
users.users.${cfg.user} = {
121+
isSystemUser = true;
122+
group = cfg.group;
123+
};
124+
users.groups.${cfg.group} = {};
125+
126+
nix-bitcoin.secrets."lndhub.go-jwt-secret".user = cfg.user;
127+
nix-bitcoin.generateSecretsCmds.lndhub-go = ''
128+
makePasswordSecret lndhub.go-jwt-secret
129+
'';
130+
};
131+
}

modules/modules.nix

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
./clightning-replication.nix
1717
./spark-wallet.nix
1818
./lnd.nix
19+
./lndhub-go.nix
1920
./lightning-loop.nix
2021
./lightning-pool.nix
2122
./charge-lnd.nix

modules/netns-isolation.nix

+6
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ in {
297297
id = 31;
298298
connections = [ "bitcoind" ];
299299
};
300+
lndhub-go = {
301+
id = 32;
302+
connections = [ "lnd" ];
303+
};
300304
};
301305

302306
services.bitcoind = {
@@ -355,6 +359,8 @@ in {
355359
services.rtl.address = netns.rtl.address;
356360

357361
services.clightning-rest.address = netns.clightning-rest.address;
362+
363+
services.lndhub-go.address = netns.lndhub-go.address;
358364
}
359365
]);
360366
}

modules/nodeinfo.nix

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ in {
138138
liquidd = mkInfo "";
139139
joinmarket-ob-watcher = mkInfo "";
140140
rtl = mkInfo "";
141+
lndhub-go = mkInfo "";
141142
# Only add sshd when it has an onion service
142143
sshd = name: cfg: mkIfOnionPort "sshd" (onionPort: ''
143144
add_service("sshd", """set_onion_address(info, "sshd", ${onionPort})""")

modules/presets/enable-tor.nix

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ in {
4040
joinmarket = defaultEnforceTor;
4141
joinmarket-ob-watcher = defaultEnforceTor;
4242
clightning-rest = defaultEnforceTor;
43+
lndhub-go = defaultEnforceTor;
4344
};
4445

4546
# Add onion services for incoming connections
@@ -51,5 +52,6 @@ in {
5152
spark-wallet.enable = defaultTrue;
5253
joinmarket-ob-watcher.enable = defaultTrue;
5354
rtl.enable = defaultTrue;
55+
lndhub-go.enable = defaultTrue;
5456
};
5557
}

pkgs/pinned.nix

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ pkgs: pkgsUnstable:
1717
fulcrum
1818
hwi
1919
lightning-loop
20-
lnd;
20+
lnd
21+
lndhub-go;
2122

2223
inherit pkgs pkgsUnstable;
2324
}

test/tests.nix

+4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ let
118118
tests.liquidd = cfg.liquidd.enable;
119119
services.liquidd.extraConfig = mkIf config.test.noConnections "connect=0";
120120

121+
tests.lndhub-go = cfg.lndhub-go.enable;
122+
121123
tests.btcpayserver = cfg.btcpayserver.enable;
122124
services.btcpayserver = {
123125
lightningBackend = mkDefault "lnd";
@@ -204,6 +206,7 @@ let
204206
services.lightning-loop.enable = true;
205207
services.lightning-pool.enable = true;
206208
services.charge-lnd.enable = true;
209+
services.lndhub-go.enable = true;
207210
services.electrs.enable = true;
208211
services.fulcrum.enable = true;
209212
services.liquidd.enable = true;
@@ -251,6 +254,7 @@ let
251254
services.lightning-loop.enable = true;
252255
services.lightning-pool.enable = true;
253256
services.charge-lnd.enable = true;
257+
services.lndhub-go.enable = true;
254258
services.electrs.enable = true;
255259
services.fulcrum.enable = true;
256260
services.btcpayserver.enable = true;

test/tests.py

+6
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ def _():
123123
def _():
124124
succeed("systemctl stop electrs")
125125

126+
@test("lndhub-go")
127+
def _():
128+
assert_running("lndhub-go")
129+
wait_for_open_port(ip("lndhub-go"), 8082)
130+
machine.wait_until_succeeds(log_has_string("lndhub-go", "Connected to LND"))
131+
126132
@test("liquidd")
127133
def _():
128134
assert_running("liquidd")

0 commit comments

Comments
 (0)