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