From c8774375d32186ca190e6f5b2e50ec881c53268c Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Mon, 13 Sep 2021 13:40:49 +0200 Subject: [PATCH] modules: use consistent service variables Benefits of adding top-level variables for used services: - Makes it obvious which other services are referenced by a service - Less code We already do this in many other places. --- modules/btcpayserver.nix | 12 +++++++----- modules/charge-lnd.nix | 2 +- modules/clightning.nix | 1 + modules/liquid.nix | 11 +++++++---- modules/lnd.nix | 1 + modules/spark-wallet.nix | 6 ++++-- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/modules/btcpayserver.nix b/modules/btcpayserver.nix index 682b5c7..aa2422f 100644 --- a/modules/btcpayserver.nix +++ b/modules/btcpayserver.nix @@ -100,6 +100,8 @@ let cfg = config.services; nbLib = config.nix-bitcoin.lib; nbPkgs = config.nix-bitcoin.pkgs; + + bitcoind = config.services.bitcoind; in { inherit options; @@ -139,10 +141,10 @@ in { systemd.services.nbxplorer = let configFile = builtins.toFile "config" '' - network=${config.services.bitcoind.network} + network=${bitcoind.network} btcrpcuser=${cfg.bitcoind.rpc.users.btcpayserver.name} - btcrpcurl=http://${config.services.bitcoind.rpc.address}:${toString cfg.bitcoind.rpc.port} - btcnodeendpoint=${config.services.bitcoind.address}:${toString config.services.bitcoind.port} + btcrpcurl=http://${bitcoind.rpc.address}:${toString cfg.bitcoind.rpc.port} + btcnodeendpoint=${bitcoind.address}:${toString bitcoind.port} bind=${cfg.nbxplorer.address} port=${toString cfg.nbxplorer.port} ${optionalString cfg.btcpayserver.lbtc '' @@ -180,9 +182,9 @@ in { systemd.services.btcpayserver = let nbExplorerUrl = "http://${cfg.nbxplorer.address}:${toString cfg.nbxplorer.port}/"; - nbExplorerCookie = "${cfg.nbxplorer.dataDir}/${config.services.bitcoind.makeNetworkName "Main" "RegTest"}/.cookie"; + nbExplorerCookie = "${cfg.nbxplorer.dataDir}/${bitcoind.makeNetworkName "Main" "RegTest"}/.cookie"; configFile = builtins.toFile "config" ('' - network=${config.services.bitcoind.network} + network=${bitcoind.network} bind=${cfg.btcpayserver.address} port=${toString cfg.btcpayserver.port} socksendpoint=${config.nix-bitcoin.torClientAddressWithPort} diff --git a/modules/charge-lnd.nix b/modules/charge-lnd.nix index 8e72478..f6579c1 100644 --- a/modules/charge-lnd.nix +++ b/modules/charge-lnd.nix @@ -69,6 +69,7 @@ let cfg = config.services.charge-lnd; nbLib = config.nix-bitcoin.lib; + lnd = config.services.lnd; electrs = if (config.services ? electrs) && config.services.electrs.enable then config.services.electrs @@ -77,7 +78,6 @@ let user = "charge-lnd"; group = user; dataDir = "/var/lib/charge-lnd"; - configFile = builtins.toFile "charge-lnd.config" cfg.policies; checkedConfig = pkgs.runCommandNoCC "charge-lnd-checked.config" { } '' ${config.nix-bitcoin.pkgs.charge-lnd}/bin/charge-lnd --check --config ${configFile} diff --git a/modules/clightning.nix b/modules/clightning.nix index 6aea551..58a59bd 100644 --- a/modules/clightning.nix +++ b/modules/clightning.nix @@ -76,6 +76,7 @@ let cfg = config.services.clightning; nbLib = config.nix-bitcoin.lib; nbPkgs = config.nix-bitcoin.pkgs; + network = config.services.bitcoind.makeNetworkName "bitcoin" "regtest"; configFile = pkgs.writeText "config" '' network=${network} diff --git a/modules/liquid.nix b/modules/liquid.nix index e2a57e8..9a311fc 100644 --- a/modules/liquid.nix +++ b/modules/liquid.nix @@ -140,9 +140,12 @@ let nbLib = config.nix-bitcoin.lib; nbPkgs = config.nix-bitcoin.pkgs; secretsDir = config.nix-bitcoin.secretsDir; + + bitcoind = config.services.bitcoind; + pidFile = "${cfg.dataDir}/liquidd.pid"; configFile = pkgs.writeText "elements.conf" '' - chain=${config.services.bitcoind.makeNetworkName "liquidv1" '' + chain=${bitcoind.makeNetworkName "liquidv1" '' regtest [regtest]'' # Add [regtest] config section } @@ -166,9 +169,9 @@ let rpcconnect=${cfg.rpc.address} ${lib.concatMapStrings (rpcallowip: "rpcallowip=${rpcallowip}\n") cfg.rpcallowip} rpcuser=${cfg.rpcuser} - mainchainrpchost=${config.services.bitcoind.rpc.address} - mainchainrpcport=${toString config.services.bitcoind.rpc.port} - mainchainrpcuser=${config.services.bitcoind.rpc.users.public.name} + mainchainrpchost=${bitcoind.rpc.address} + mainchainrpcport=${toString bitcoind.rpc.port} + mainchainrpcuser=${bitcoind.rpc.users.public.name} # Extra config options (from liquidd nixos service) ${cfg.extraConfig} diff --git a/modules/lnd.nix b/modules/lnd.nix index 7c1a84f..7e93113 100644 --- a/modules/lnd.nix +++ b/modules/lnd.nix @@ -128,6 +128,7 @@ let runAsUser = config.nix-bitcoin.runAsUserCmd; bitcoind = config.services.bitcoind; + bitcoindRpcAddress = bitcoind.rpc.address; networkDir = "${cfg.dataDir}/chain/bitcoin/${bitcoind.network}"; configFile = pkgs.writeText "lnd.conf" '' diff --git a/modules/spark-wallet.nix b/modules/spark-wallet.nix index 0ca153c..a55be9a 100644 --- a/modules/spark-wallet.nix +++ b/modules/spark-wallet.nix @@ -44,6 +44,8 @@ let cfg = config.services.spark-wallet; nbLib = config.nix-bitcoin.lib; + clightning = config.services.clightning; + # Use wasabi rate provider because the default (bitstamp) doesn't accept # connections through Tor torRateProvider = "--rate-provider wasabi --proxy socks5h://${config.nix-bitcoin.torClientAddressWithPort}"; @@ -52,7 +54,7 @@ let publicURL="--public-url http://$(${cfg.getPublicAddressCmd})" ''} exec ${config.nix-bitcoin.pkgs.spark-wallet}/bin/spark-wallet \ - --ln-path '${config.services.clightning.networkDir}' \ + --ln-path '${clightning.networkDir}' \ --host ${cfg.address} --port ${toString cfg.port} \ --config '${config.nix-bitcoin.secretsDir}/spark-wallet-login' \ ${optionalString cfg.enforceTor torRateProvider} \ @@ -81,7 +83,7 @@ in { users.users.${cfg.user} = { isSystemUser = true; group = cfg.group; - extraGroups = [ config.services.clightning.group ]; + extraGroups = [ clightning.group ]; }; users.groups.${cfg.group} = {};