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

lnd: add option for configuring REST port #188

Merged
merged 1 commit into from
Jun 7, 2020
Merged
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
18 changes: 13 additions & 5 deletions modules/lnd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let
tlskeypath=${secretsDir}/lnd-key

rpclisten=localhost:${toString cfg.rpcPort}
restlisten=localhost:${toString cfg.restPort}

bitcoin.active=1
bitcoin.node=bitcoind
Expand Down Expand Up @@ -49,6 +50,11 @@ in {
default = 10009;
description = "Port on which to listen for gRPC connections.";
};
restPort = mkOption {
type = types.port;
default = 8080;
description = "Port on which to listen for REST connections.";
};
extraConfig = mkOption {
type = types.lines;
default = "";
Expand Down Expand Up @@ -104,11 +110,13 @@ in {
Restart = "on-failure";
RestartSec = "10s";
ReadWritePaths = "${cfg.dataDir}";
ExecStartPost = [
ExecStartPost = let
restPort = toString cfg.restPort;
in [
# Run fully privileged for secrets dir write access
"+${nix-bitcoin-services.script ''
attempts=50
while ! { exec 3>/dev/tcp/127.0.0.1/8080 && exec 3>&-; } &>/dev/null; do
while ! { exec 3>/dev/tcp/127.0.0.1/${restPort} && exec 3>&-; } &>/dev/null; do
((attempts-- == 0)) && { echo "lnd REST service unreachable"; exit 1; }
sleep 0.1
done
Expand All @@ -119,7 +127,7 @@ in {

${pkgs.curl}/bin/curl -s \
--cacert ${secretsDir}/lnd-cert \
-X GET https://127.0.0.1:8080/v1/genseed | ${pkgs.jq}/bin/jq -c '.cipher_seed_mnemonic' > "$mnemonic"
-X GET https://127.0.0.1:${restPort}/v1/genseed | ${pkgs.jq}/bin/jq -c '.cipher_seed_mnemonic' > "$mnemonic"
fi
chown lnd: "$mnemonic"
chmod 400 "$mnemonic"
Expand All @@ -134,7 +142,7 @@ in {
--cacert ${secretsDir}/lnd-cert \
-X POST -d "{\"wallet_password\": \"$(cat ${secretsDir}/lnd-wallet-password | tr -d '\n' | base64 -w0)\", \
\"cipher_seed_mnemonic\": $(cat ${secretsDir}/lnd-seed-mnemonic | tr -d '\n')}" \
https://127.0.0.1:8080/v1/initwallet
https://127.0.0.1:${restPort}/v1/initwallet

# Guarantees that RPC calls with cfg.cli succeed after the service is started
echo Wait until wallet is created
Expand All @@ -149,7 +157,7 @@ in {
--cacert ${secretsDir}/lnd-cert \
-X POST \
-d "{\"wallet_password\": \"$(cat ${secretsDir}/lnd-wallet-password | tr -d '\n' | base64 -w0)\"}" \
https://127.0.0.1:8080/v1/unlockwallet
https://127.0.0.1:${restPort}/v1/unlockwallet
fi

# Wait until the RPC port is open
Expand Down