-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lndhub-go: integrate LndHub.go into Nix-Bitcoin
- Loading branch information
Showing
10 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
let | ||
options.services = { | ||
lndhub-go = { | ||
enable = mkEnableOption "LndHub.go, an accounting wrapper for the Lightning Network"; | ||
address = mkOption { | ||
type = types.str; | ||
default = "127.0.0.1"; | ||
description = "Address to listen on."; | ||
}; | ||
port = mkOption { | ||
type = types.port; | ||
default = 3001; | ||
description = "Port to listen on."; | ||
}; | ||
feeReserve = mkOption { | ||
type = types.bool; | ||
default = false; | ||
description = "Keep fee reserve for each user."; | ||
}; | ||
allowAccountCreation = mkOption { | ||
type = types.bool; | ||
default = true; | ||
description = "Enable creation of new accounts."; | ||
}; | ||
dataDir = mkOption { | ||
type = types.path; | ||
default = "/var/lib/lndhub-go"; | ||
description = "The data directory for LndHub.go."; | ||
}; | ||
user = mkOption { | ||
type = types.str; | ||
default = "lndhub-go"; | ||
description = "The user as which to run LndHub.go."; | ||
}; | ||
group = mkOption { | ||
type = types.str; | ||
default = cfg.lndhub-go.user; | ||
description = "The group as which to run LndHub.go."; | ||
}; | ||
tor.enforce = nbLib.tor.enforce; | ||
}; | ||
}; | ||
|
||
cfg = config.services; | ||
nbLib = config.nix-bitcoin.lib; | ||
|
||
in { | ||
inherit options; | ||
|
||
config = mkIf cfg.lndhub-go.enable { | ||
services.lnd = { | ||
enable = true; | ||
macaroons.lndhub-go = { | ||
inherit (cfg.lndhub-go) 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 = [ "lndhub-go" ]; | ||
ensureUsers = [ | ||
{ | ||
name = cfg.lndhub-go.user; | ||
ensurePermissions."DATABASE lndhub-go" = "ALL PRIVILEGES"; | ||
} | ||
]; | ||
}; | ||
|
||
systemd.services.lndhub-go = { | ||
wantedBy = [ "multi-user.target" ]; | ||
requires = [ "lnd.service" "postgresql.service" ]; | ||
after = self.requires; | ||
preStart = '' | ||
mkdir -p '${cfg.lndhub-go.dataDir}'; | ||
{ | ||
echo "DATABASE_URI=postgresql://${cfg.lndhub-go.user}:@localhost:${cfg.postgresql.port}/lndhub-go?sslmode=disable" | ||
echo "JWT_SECRET=$(cat ${config.nix-bitcoin.secretsDir}/lndhub.go-jwt_secret)" | ||
echo "LND_ADDRESS="${cfg.lnd.address}:${toString cfg.lnd.port}" | ||
echo "LND_MACAROON_HEX=$(xxd -p -c 9999 /run/lnd/lndhub-go.macaroon)" | ||
echo "LND_CERT_HEX=$(xxd -p -c 9999 ${cfg.lnd.certPath})" | ||
echo "HOST=${cfg.lndhub-go.address}" | ||
echo "PORT=${toString cfg.lndhub-go.port}" | ||
echo "FEE_RESERVE=${cfg.lndhub-go.feeReserve}" | ||
echo "ALLOW_ACCOUNT_CREATION=${cfg.lndhub-go.allowAccountCreation}" | ||
echo "BRANDING_TITLE=LndHub.go - Nix-Bitcoin" | ||
echo "BRANDING_DESC=Accounting wrapper for the Lightning Network" | ||
echo "BRANDING_URL=https://nixbitcoin.org" | ||
echo "BRANDING_LOGO=https://nixbitcoin.org/files/nix-bitcoin-logo-text.png" | ||
echo "BRANDING_FAVICON=https://nixbitcoin.org/files/nix-bitcoin-logo.png" | ||
echo "BRANDING_FOOTER=about=https://nixbitcoin.org,github=https://github.com/fort-nix/nix-bitcoin" | ||
} > '${cfg.lndhub-go.dataDir}/lndhub-go.env' | ||
chmod 600 '${cfg.lndhub-go.dataDir}/lndhub-go.env' | ||
''; | ||
serviceConfig = nbLib.defaultHardening // { | ||
EnvironmentFile = "${cfg.lndhub-go.dataDir}/lndhub-go.env"; | ||
ExecStart = '' | ||
${cfg.lndhub-go.package}/bin/lndhub.go | ||
''; | ||
User = cfg.lndhub-go.user; | ||
Restart = "on-failure"; | ||
RestartSec = "10s"; | ||
} // nbLib.allowedIPAddresses cfg.lndhub-go.tor.enforce; | ||
}; | ||
|
||
users.users.${cfg.lndhub-go.user} = { | ||
isSystemUser = true; | ||
group = cfg.lndhub-go.group; | ||
}; | ||
users.groups.${cfg.lndhub-go.group} = {}; | ||
nix-bitcoin.generateSecretsCmds.lndhub-go = '' | ||
makePasswordSecret lndhub.go-jwt_secret | ||
''; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ pkgs: pkgsUnstable: | |
hwi | ||
lightning-loop | ||
lnd | ||
lndhub-go | ||
nbxplorer; | ||
|
||
inherit pkgs pkgsUnstable; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters