Skip to content

Commit

Permalink
lnd: add option for configuring REST port
Browse files Browse the repository at this point in the history
  • Loading branch information
mmilata committed Jun 3, 2020
1 parent 8cc0b30 commit 03a627a
Showing 1 changed file with 13 additions and 5 deletions.
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

0 comments on commit 03a627a

Please sign in to comment.