Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lndhub-go: integrate LndHub.go #519

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ NixOS modules ([src](modules/modules.nix))
* [Lightning Loop](https://github.com/lightninglabs/loop)
* [Lightning Pool](https://github.com/lightninglabs/pool)
* [charge-lnd](https://github.com/accumulator/charge-lnd): policy-based channel fee manager
* [LndHub.go](https://github.com/getAlby/lndhub.go): accounting wrapper for lnd
* [lndconnect](https://github.com/LN-Zap/lndconnect): connect your wallet to lnd or clightning via a REST onion service
* [Ride The Lightning](https://github.com/Ride-The-Lightning/RTL): web interface for `lnd` and `clightning`
* [spark-wallet](https://github.com/shesek/spark-wallet)
Expand Down
5 changes: 5 additions & 0 deletions examples/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@
#
# services.fulcrum.enable = true;

### LNDHUB.GO
# Set this to enable LndHub.go, an accounting wrapper for the Lightning Network.
#
# services.lndhub-go.enable = true;

### BTCPayServer
# Set this to enable BTCPayServer, a self-hosted, open-source
# cryptocurrency payment processor.
Expand Down
131 changes: 131 additions & 0 deletions modules/lndhub-go.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{ config, lib, pkgs, ... }:

with lib;
let
options.services = {
lndhub-go = {
enable = mkEnableOption "LndHub.go, an accounting wrapper for lnd";
address = mkOption {
type = types.str;
default = "127.0.0.1";
description = "Address to listen on.";
};
port = mkOption {
type = types.port;
default = 8082;
description = "Port to listen on.";
};
settings = mkOption {
type = with types; attrsOf (oneOf [ str int bool ]);
example = {
ALLOW_ACCOUNT_CREATION = false;
FEE_RESERVE = true;
MAX_SEND_AMOUNT = 1000000;
};
description = ''
LndHub.go settings.
See here for possible options:
https://github.com/getAlby/lndhub.go#available-configuration
'';
};
package = mkOption {
type = types.package;
default = config.nix-bitcoin.pkgs.lndhub-go;
defaultText = "config.nix-bitcoin.pkgs.lndhub-go";
description = "The package providing LndHub.go binaries.";
};
user = mkOption {
type = types.str;
default = "lndhub-go";
description = "The user as which to run LndHub.go.";
};
group = mkOption {
type = types.str;
default = cfg.user;
description = "The group as which to run LndHub.go.";
};
tor.enforce = nbLib.tor.enforce;
};
};

cfg = config.services.lndhub-go;
nbLib = config.nix-bitcoin.lib;

inherit (config.services)
lnd
postgresql;

configFile = builtins.toFile "lndhub-go-conf" (lib.generators.toKeyValue {} cfg.settings);

dbName = "lndhub-go";
in {
inherit options;

config = mkIf cfg.enable {
services.lnd = {
enable = true;
macaroons.lndhub-go = {
inherit (cfg) user;
permissions = ''{"entity":"info","action":"read"},{"entity":"invoices","action":"read"},{"entity":"invoices","action":"write"},{"entity":"offchain","action":"read"},{"entity":"offchain","action":"write"}'';
};
};
services.postgresql = {
enable = true;
ensureDatabases = [ dbName ];
ensureUsers = [
{
name = cfg.user;
ensurePermissions."DATABASE \"${dbName}\"" = "ALL PRIVILEGES";
}
];
};

services.lndhub-go.settings = {
HOST = cfg.address;
PORT = cfg.port;
DATABASE_URI = "unix://${cfg.user}@${dbName}/run/postgresql/.s.PGSQL.${toString postgresql.port}?sslmode=disable";
LND_ADDRESS = "${nbLib.addressWithPort lnd.address lnd.rpcPort}";
LND_MACAROON_FILE = "/run/lnd/lndhub-go.macaroon";
LND_CERT_FILE = lnd.certPath;
BRANDING_TITLE = "LndHub.go - Nix-Bitcoin";
BRANDING_DESC = "Accounting wrapper for the Lightning Network";
BRANDING_URL = "https://nixbitcoin.org";
BRANDING_LOGO = "https://nixbitcoin.org/files/nix-bitcoin-logo-text.png";
prusnak marked this conversation as resolved.
Show resolved Hide resolved
BRANDING_FAVICON = "https://nixbitcoin.org/files/nix-bitcoin-logo.png";
BRANDING_FOOTER = "about=https://nixbitcoin.org;github=https://github.com/fort-nix/nix-bitcoin";
};

systemd.services.lndhub-go = rec {
wantedBy = [ "multi-user.target" ];
requires = [ "lnd.service" "postgresql.service" ];
after = requires;
preStart = ''
{
cat ${configFile}
echo "JWT_SECRET=$(cat '${config.nix-bitcoin.secretsDir}/lndhub.go-jwt-secret')"
} > .env
'';
serviceConfig = nbLib.defaultHardening // {
StateDirectory = "lndhub-go";
StateDirectoryMode = "770";
# lndhub-go reads file `.env` from the working directory
WorkingDirectory = "/var/lib/lndhub-go";
ExecStart = "${config.nix-bitcoin.pkgs.lndhub-go}/bin/lndhub.go";
User = cfg.user;
Restart = "on-failure";
RestartSec = "10s";
} // nbLib.allowedIPAddresses cfg.tor.enforce;
};

users.users.${cfg.user} = {
isSystemUser = true;
group = cfg.group;
};
users.groups.${cfg.group} = {};

nix-bitcoin.secrets."lndhub.go-jwt-secret".user = cfg.user;
nix-bitcoin.generateSecretsCmds.lndhub-go = ''
makePasswordSecret lndhub.go-jwt-secret
'';
};
}
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
./clightning-replication.nix
./spark-wallet.nix
./lnd.nix
./lndhub-go.nix
./lightning-loop.nix
./lightning-pool.nix
./charge-lnd.nix
Expand Down
6 changes: 6 additions & 0 deletions modules/netns-isolation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ in {
id = 31;
connections = [ "bitcoind" ];
};
lndhub-go = {
id = 32;
connections = [ "lnd" ];
};
};

services.bitcoind = {
Expand Down Expand Up @@ -355,6 +359,8 @@ in {
services.rtl.address = netns.rtl.address;

services.clightning-rest.address = netns.clightning-rest.address;

services.lndhub-go.address = netns.lndhub-go.address;
}
]);
}
1 change: 1 addition & 0 deletions modules/nodeinfo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ in {
liquidd = mkInfo "";
joinmarket-ob-watcher = mkInfo "";
rtl = mkInfo "";
lndhub-go = 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})""")
Expand Down
2 changes: 2 additions & 0 deletions modules/presets/enable-tor.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ in {
joinmarket = defaultEnforceTor;
joinmarket-ob-watcher = defaultEnforceTor;
clightning-rest = defaultEnforceTor;
lndhub-go = defaultEnforceTor;
};

# Add onion services for incoming connections
Expand All @@ -51,5 +52,6 @@ in {
spark-wallet.enable = defaultTrue;
joinmarket-ob-watcher.enable = defaultTrue;
rtl.enable = defaultTrue;
lndhub-go.enable = defaultTrue;
};
}
1 change: 1 addition & 0 deletions pkgs/pinned.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pkgs: pkgsUnstable:
hwi
lightning-loop
lnd
lndhub-go
nbxplorer;

inherit pkgs pkgsUnstable;
Expand Down
4 changes: 4 additions & 0 deletions test/tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ let
tests.liquidd = cfg.liquidd.enable;
services.liquidd.extraConfig = mkIf config.test.noConnections "connect=0";

tests.lndhub-go = cfg.lndhub-go.enable;

tests.btcpayserver = cfg.btcpayserver.enable;
services.btcpayserver = {
lightningBackend = mkDefault "lnd";
Expand Down Expand Up @@ -191,6 +193,7 @@ let
services.lightning-loop.enable = true;
services.lightning-pool.enable = true;
services.charge-lnd.enable = true;
services.lndhub-go.enable = true;
services.electrs.enable = true;
services.fulcrum.enable = true;
services.liquidd.enable = true;
Expand Down Expand Up @@ -238,6 +241,7 @@ let
services.lightning-loop.enable = true;
services.lightning-pool.enable = true;
services.charge-lnd.enable = true;
services.lndhub-go.enable = true;
services.electrs.enable = true;
services.fulcrum.enable = true;
services.btcpayserver.enable = true;
Expand Down
6 changes: 6 additions & 0 deletions test/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ def _():
def _():
succeed("systemctl stop electrs")

@test("lndhub-go")
def _():
assert_running("lndhub-go")
wait_for_open_port(ip("lndhub-go"), 8082)
machine.wait_until_succeeds(log_has_string("lndhub-go", "Connected to LND"))

@test("liquidd")
def _():
assert_running("liquidd")
Expand Down