electrs: add netns

- Adds electrs to netns-isolation.services
- Adds daemonrpc option and specifies address option to allow using
  electrs with network namespaces
- Adds host option (defaults to localhost) as target of hidden service
This commit is contained in:
nixbitcoin 2020-05-29 11:13:50 +00:00
parent c0b02ac93a
commit d6296acaba
No known key found for this signature in database
GPG Key ID: DD11F9AD5308B3BA
3 changed files with 30 additions and 1 deletions

View File

@ -17,6 +17,14 @@ in {
default = "/var/lib/electrs"; default = "/var/lib/electrs";
description = "The data directory for electrs."; description = "The data directory for electrs.";
}; };
# Needed until electrs tls proxy is removed
host = mkOption {
type = types.str;
default = "localhost";
description = ''
The host on which incoming connections arrive.
'';
};
user = mkOption { user = mkOption {
type = types.str; type = types.str;
default = "electrs"; default = "electrs";
@ -44,6 +52,13 @@ in {
default = 50001; default = 50001;
description = "RPC port."; description = "RPC port.";
}; };
daemonrpc = mkOption {
type = types.str;
default = "127.0.0.1:8332";
description = ''
Bitcoin daemon JSONRPC 'addr:port' to connect
'';
};
extraArgs = mkOption { extraArgs = mkOption {
type = types.separatedString " "; type = types.separatedString " ";
default = ""; default = "";
@ -97,7 +112,8 @@ in {
"--jsonrpc-import --index-batch-size=10" "--jsonrpc-import --index-batch-size=10"
} \ } \
--db-dir '${cfg.dataDir}' --daemon-dir '${config.services.bitcoind.dataDir}' \ --db-dir '${cfg.dataDir}' --daemon-dir '${config.services.bitcoind.dataDir}' \
--electrum-rpc-addr=${toString cfg.address}:${toString cfg.port} ${cfg.extraArgs} --electrum-rpc-addr=${toString cfg.address}:${toString cfg.port} \
--daemon-rpc-addr=${toString cfg.daemonrpc} ${cfg.extraArgs}
''; '';
User = cfg.user; User = cfg.user;
Group = cfg.group; Group = cfg.group;

View File

@ -100,6 +100,11 @@ in {
id = 15; id = 15;
connections = [ "bitcoind" ]; connections = [ "bitcoind" ];
}; };
electrs = {
id = 16;
connections = [ "bitcoind" ]
++ ( optionals config.services.electrs.TLSProxy.enable [ "nginx" ]);
};
}; };
systemd.services = { systemd.services = {
@ -240,6 +245,13 @@ in {
''; '';
}; };
# electrs: Custom netns configs
services.electrs = mkIf config.services.electrs.enable {
host = if config.services.electrs.TLSProxy.enable then netns.nginx.address else netns.electrs.address;
address = netns.electrs.address;
daemonrpc = "${netns.bitcoind.address}:${toString config.services.bitcoind.rpc.port}";
};
}) })
# Custom netns config option values if netns-isolation not enabled # Custom netns config option values if netns-isolation not enabled
(mkIf (!cfg.enable) { (mkIf (!cfg.enable) {

View File

@ -119,6 +119,7 @@ in {
services.tor.hiddenServices.electrs = mkHiddenService { services.tor.hiddenServices.electrs = mkHiddenService {
port = cfg.electrs.onionport; port = cfg.electrs.onionport;
toPort = if cfg.electrs.TLSProxy.enable then cfg.electrs.TLSProxy.port else cfg.electrs.port; toPort = if cfg.electrs.TLSProxy.enable then cfg.electrs.TLSProxy.port else cfg.electrs.port;
toHost = cfg.electrs.host;
}; };
services.spark-wallet.onion-service = true; services.spark-wallet.onion-service = true;