mirror of
https://github.com/fort-nix/nix-bitcoin.git
synced 2024-11-22 22:33:46 +03:00
services: support 0.0.0.0/:: in address
options
Previously, client services didn't decode these special INADDR_ANY addresses and failed to connect.
This commit is contained in:
parent
1848c3dd98
commit
f61e928139
@ -143,15 +143,15 @@ in {
|
||||
configFile = builtins.toFile "config" ''
|
||||
network=${bitcoind.network}
|
||||
btcrpcuser=${cfg.bitcoind.rpc.users.btcpayserver.name}
|
||||
btcrpcurl=http://${bitcoind.rpc.address}:${toString cfg.bitcoind.rpc.port}
|
||||
btcnodeendpoint=${bitcoind.address}:${toString bitcoind.port}
|
||||
btcrpcurl=http://${nbLib.addressWithPort bitcoind.rpc.address cfg.bitcoind.rpc.port}
|
||||
btcnodeendpoint=${nbLib.addressWithPort bitcoind.address bitcoind.port}
|
||||
bind=${cfg.nbxplorer.address}
|
||||
port=${toString cfg.nbxplorer.port}
|
||||
${optionalString cfg.btcpayserver.lbtc ''
|
||||
chains=btc,lbtc
|
||||
lbtcrpcuser=${liquidd.rpcuser}
|
||||
lbtcrpcurl=http://${liquidd.rpc.address}:${toString liquidd.rpc.port}
|
||||
lbtcnodeendpoint=${liquidd.address}:${toString liquidd.port}
|
||||
lbtcrpcurl=http://${nbLib.addressWithPort liquidd.rpc.address liquidd.rpc.port}
|
||||
lbtcnodeendpoint=${nbLib.addressWithPort liquidd.address liquidd.port}
|
||||
''}
|
||||
'';
|
||||
in {
|
||||
|
@ -112,9 +112,10 @@ in
|
||||
ExecStart = ''
|
||||
${config.nix-bitcoin.pkgs.charge-lnd}/bin/charge-lnd \
|
||||
--lnddir ${dataDir}/lnddir-proxy \
|
||||
--grpc ${lnd.rpcAddress}:${toString lnd.rpcPort} \
|
||||
--grpc ${nbLib.addressWithPort lnd.rpcAddress lnd.rpcPort} \
|
||||
--config ${checkedConfig} \
|
||||
${optionalString (electrs != null) "--electrum-server ${electrs.address}:${toString electrs.port}"} \
|
||||
${optionalString (electrs != null)
|
||||
"--electrum-server ${nbLib.addressWithPort electrs.address electrs.port}"} \
|
||||
${escapeShellArgs cfg.extraFlags}
|
||||
'';
|
||||
Type = "oneshot";
|
||||
|
@ -84,7 +84,7 @@ let
|
||||
${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"}
|
||||
always-use-proxy=${boolToString cfg.always-use-proxy}
|
||||
bind-addr=${cfg.address}:${toString cfg.port}
|
||||
bitcoin-rpcconnect=${config.services.bitcoind.rpc.address}
|
||||
bitcoin-rpcconnect=${nbLib.address config.services.bitcoind.rpc.address}
|
||||
bitcoin-rpcport=${toString config.services.bitcoind.rpc.port}
|
||||
bitcoin-rpcuser=${config.services.bitcoind.rpc.users.public.name}
|
||||
rpc-file-mode=0660
|
||||
|
@ -96,7 +96,7 @@ in {
|
||||
--daemon-dir='${bitcoind.dataDir}' \
|
||||
--electrum-rpc-addr=${cfg.address}:${toString cfg.port} \
|
||||
--monitoring-addr=${cfg.address}:${toString cfg.monitoringPort} \
|
||||
--daemon-rpc-addr=${bitcoind.rpc.address}:${toString bitcoind.rpc.port} \
|
||||
--daemon-rpc-addr=${nbLib.addressWithPort bitcoind.rpc.address bitcoind.rpc.port} \
|
||||
${cfg.extraArgs}
|
||||
'';
|
||||
User = cfg.user;
|
||||
|
@ -124,7 +124,7 @@ let
|
||||
[BLOCKCHAIN]
|
||||
blockchain_source = bitcoin-rpc
|
||||
network = ${bitcoind.network}
|
||||
rpc_host = ${bitcoind.rpc.address}
|
||||
rpc_host = ${nbLib.address bitcoind.rpc.address}
|
||||
rpc_port = ${toString bitcoind.rpc.port}
|
||||
rpc_user = ${bitcoind.rpc.users.privileged.name}
|
||||
${optionalString (cfg.rpcWalletFile != null) "rpc_wallet_file = ${cfg.rpcWalletFile}"}
|
||||
|
@ -50,7 +50,7 @@ let
|
||||
cli = mkOption {
|
||||
default = pkgs.writeScriptBin "loop" ''
|
||||
${cfg.package}/bin/loop \
|
||||
--rpcserver ${rpclisten} \
|
||||
--rpcserver ${nbLib.addressWithPort cfg.rpcAddress cfg.rpcPort} \
|
||||
--macaroonpath '${cfg.dataDir}/${network}/loop.macaroon' \
|
||||
--tlscertpath '${secretsDir}/loop-cert' "$@"
|
||||
'';
|
||||
@ -66,17 +66,16 @@ let
|
||||
lnd = config.services.lnd;
|
||||
|
||||
network = config.services.bitcoind.network;
|
||||
rpclisten = "${cfg.rpcAddress}:${toString cfg.rpcPort}";
|
||||
configFile = builtins.toFile "loop.conf" ''
|
||||
datadir=${cfg.dataDir}
|
||||
network=${network}
|
||||
rpclisten=${rpclisten}
|
||||
rpclisten=${cfg.rpcAddress}:${toString cfg.rpcPort}
|
||||
restlisten=${cfg.restAddress}:${toString cfg.restPort}
|
||||
logdir=${cfg.dataDir}/logs
|
||||
tlscertpath=${secretsDir}/loop-cert
|
||||
tlskeypath=${secretsDir}/loop-key
|
||||
|
||||
lnd.host=${lnd.rpcAddress}:${toString lnd.rpcPort}
|
||||
lnd.host=${nbLib.addressWithPort lnd.rpcAddress lnd.rpcPort}
|
||||
lnd.macaroonpath=${lnd.networkDir}/admin.macaroon
|
||||
lnd.tlspath=${lnd.certPath}
|
||||
|
||||
|
@ -50,7 +50,7 @@ let
|
||||
cli = mkOption {
|
||||
default = pkgs.writeScriptBin "pool" ''
|
||||
exec ${cfg.package}/bin/pool \
|
||||
--rpcserver ${rpclisten} \
|
||||
--rpcserver ${nbLib.addressWithPort cfg.rpcAddress cfg.rpcPort} \
|
||||
--network ${network} \
|
||||
--basedir '${cfg.dataDir}' "$@"
|
||||
'';
|
||||
@ -65,9 +65,8 @@ let
|
||||
lnd = config.services.lnd;
|
||||
|
||||
network = config.services.bitcoind.network;
|
||||
rpclisten = "${cfg.rpcAddress}:${toString cfg.rpcPort}";
|
||||
configFile = builtins.toFile "pool.conf" ''
|
||||
rpclisten=${rpclisten}
|
||||
rpclisten=${cfg.rpcAddress}:${toString cfg.rpcPort}
|
||||
restlisten=${cfg.restAddress}:${toString cfg.restPort}
|
||||
${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"}
|
||||
|
||||
|
@ -169,7 +169,7 @@ let
|
||||
rpcconnect=${cfg.rpc.address}
|
||||
${lib.concatMapStrings (rpcallowip: "rpcallowip=${rpcallowip}\n") cfg.rpcallowip}
|
||||
rpcuser=${cfg.rpcuser}
|
||||
mainchainrpchost=${bitcoind.rpc.address}
|
||||
mainchainrpchost=${nbLib.address bitcoind.rpc.address}
|
||||
mainchainrpcport=${toString bitcoind.rpc.port}
|
||||
mainchainrpcuser=${bitcoind.rpc.users.public.name}
|
||||
|
||||
|
@ -41,7 +41,7 @@ in {
|
||||
services.tor = {
|
||||
enable = true;
|
||||
relay.onionServices.lnd-rest = nbLib.mkOnionService {
|
||||
target.addr = lnd.restAddress;
|
||||
target.addr = nbLib.address lnd.restAddress;
|
||||
target.port = lnd.restPort;
|
||||
port = lnd.restPort;
|
||||
};
|
||||
|
@ -127,7 +127,7 @@ let
|
||||
|
||||
bitcoind = config.services.bitcoind;
|
||||
|
||||
bitcoindRpcAddress = bitcoind.rpc.address;
|
||||
bitcoindRpcAddress = nbLib.address bitcoind.rpc.address;
|
||||
networkDir = cfg.networkDir;
|
||||
configFile = pkgs.writeText "lnd.conf" ''
|
||||
datadir=${cfg.dataDir}
|
||||
@ -217,12 +217,12 @@ in {
|
||||
# existing, but the RPC service isn't yet, which results in error
|
||||
# "waiting to start, RPC services not available".
|
||||
curl = "${pkgs.curl}/bin/curl -s --show-error --retry 10 --cacert ${cfg.certPath}";
|
||||
restUrl = "https://${cfg.restAddress}:${toString cfg.restPort}/v1";
|
||||
restUrl = "https://${nbLib.addressWithPort cfg.restAddress cfg.restPort}/v1";
|
||||
in [
|
||||
(nbLib.script "lnd-create-wallet" ''
|
||||
attempts=250
|
||||
while ! {
|
||||
exec 3>/dev/tcp/${cfg.restAddress}/${toString cfg.restPort} && exec 3>&-
|
||||
exec 3>/dev/tcp/${nbLib.address cfg.restAddress}/${toString cfg.restPort} && exec 3>&-
|
||||
} &>/dev/null; do
|
||||
((attempts-- == 0)) && { echo "lnd REST service unreachable"; exit 1; }
|
||||
sleep 0.1
|
||||
|
@ -13,6 +13,7 @@ let
|
||||
};
|
||||
|
||||
cfg = config.nix-bitcoin.nodeinfo;
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
|
||||
# Services included in the output
|
||||
services = {
|
||||
@ -96,7 +97,7 @@ let
|
||||
mkInfo = extraCode: name: cfg:
|
||||
''
|
||||
add_service("${name}", """
|
||||
info["local_address"] = "${cfg.address}:${toString cfg.port}"
|
||||
info["local_address"] = "${nbLib.addressWithPort cfg.address cfg.port}"
|
||||
'' + mkIfOnionPort name (onionPort: ''
|
||||
set_onion_address(info, "${name}", ${onionPort})
|
||||
'') + extraCode + ''
|
||||
|
@ -65,7 +65,7 @@ in {
|
||||
in nbLib.mkOnionService {
|
||||
port = if externalPort != null then externalPort else service.port;
|
||||
target.port = service.port;
|
||||
target.addr = if service.address == "0.0.0.0" then "127.0.0.1" else service.address;
|
||||
target.addr = nbLib.address service.address;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
13
pkgs/lib.nix
13
pkgs/lib.nix
@ -83,4 +83,17 @@ let self = {
|
||||
map = [ map ];
|
||||
version = 3;
|
||||
};
|
||||
|
||||
# Convert a bind address, which may be a special INADDR_ANY address,
|
||||
# to an actual IP address
|
||||
address = addr:
|
||||
if addr == "0.0.0.0" then
|
||||
"127.0.0.1"
|
||||
else if addr == "::" then
|
||||
"::1"
|
||||
else
|
||||
addr;
|
||||
|
||||
addressWithPort = addr: port: "${self.address addr}:${toString port}";
|
||||
|
||||
}; in self
|
||||
|
Loading…
Reference in New Issue
Block a user