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.
This commit is contained in:
Erik Arvstedt 2021-09-13 13:40:49 +02:00
parent ad97c268c6
commit c8774375d3
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
6 changed files with 21 additions and 12 deletions

View File

@ -100,6 +100,8 @@ let
cfg = config.services; cfg = config.services;
nbLib = config.nix-bitcoin.lib; nbLib = config.nix-bitcoin.lib;
nbPkgs = config.nix-bitcoin.pkgs; nbPkgs = config.nix-bitcoin.pkgs;
bitcoind = config.services.bitcoind;
in { in {
inherit options; inherit options;
@ -139,10 +141,10 @@ in {
systemd.services.nbxplorer = let systemd.services.nbxplorer = let
configFile = builtins.toFile "config" '' configFile = builtins.toFile "config" ''
network=${config.services.bitcoind.network} network=${bitcoind.network}
btcrpcuser=${cfg.bitcoind.rpc.users.btcpayserver.name} btcrpcuser=${cfg.bitcoind.rpc.users.btcpayserver.name}
btcrpcurl=http://${config.services.bitcoind.rpc.address}:${toString cfg.bitcoind.rpc.port} btcrpcurl=http://${bitcoind.rpc.address}:${toString cfg.bitcoind.rpc.port}
btcnodeendpoint=${config.services.bitcoind.address}:${toString config.services.bitcoind.port} btcnodeendpoint=${bitcoind.address}:${toString 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 ''
@ -180,9 +182,9 @@ in {
systemd.services.btcpayserver = let systemd.services.btcpayserver = let
nbExplorerUrl = "http://${cfg.nbxplorer.address}:${toString cfg.nbxplorer.port}/"; 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" ('' configFile = builtins.toFile "config" (''
network=${config.services.bitcoind.network} network=${bitcoind.network}
bind=${cfg.btcpayserver.address} bind=${cfg.btcpayserver.address}
port=${toString cfg.btcpayserver.port} port=${toString cfg.btcpayserver.port}
socksendpoint=${config.nix-bitcoin.torClientAddressWithPort} socksendpoint=${config.nix-bitcoin.torClientAddressWithPort}

View File

@ -69,6 +69,7 @@ let
cfg = config.services.charge-lnd; cfg = config.services.charge-lnd;
nbLib = config.nix-bitcoin.lib; nbLib = config.nix-bitcoin.lib;
lnd = config.services.lnd; lnd = config.services.lnd;
electrs = if (config.services ? electrs) && config.services.electrs.enable electrs = if (config.services ? electrs) && config.services.electrs.enable
then config.services.electrs then config.services.electrs
@ -77,7 +78,6 @@ let
user = "charge-lnd"; user = "charge-lnd";
group = user; group = user;
dataDir = "/var/lib/charge-lnd"; dataDir = "/var/lib/charge-lnd";
configFile = builtins.toFile "charge-lnd.config" cfg.policies; configFile = builtins.toFile "charge-lnd.config" cfg.policies;
checkedConfig = pkgs.runCommandNoCC "charge-lnd-checked.config" { } '' checkedConfig = pkgs.runCommandNoCC "charge-lnd-checked.config" { } ''
${config.nix-bitcoin.pkgs.charge-lnd}/bin/charge-lnd --check --config ${configFile} ${config.nix-bitcoin.pkgs.charge-lnd}/bin/charge-lnd --check --config ${configFile}

View File

@ -76,6 +76,7 @@ let
cfg = config.services.clightning; cfg = config.services.clightning;
nbLib = config.nix-bitcoin.lib; nbLib = config.nix-bitcoin.lib;
nbPkgs = config.nix-bitcoin.pkgs; nbPkgs = config.nix-bitcoin.pkgs;
network = config.services.bitcoind.makeNetworkName "bitcoin" "regtest"; network = config.services.bitcoind.makeNetworkName "bitcoin" "regtest";
configFile = pkgs.writeText "config" '' configFile = pkgs.writeText "config" ''
network=${network} network=${network}

View File

@ -140,9 +140,12 @@ let
nbLib = config.nix-bitcoin.lib; nbLib = config.nix-bitcoin.lib;
nbPkgs = config.nix-bitcoin.pkgs; nbPkgs = config.nix-bitcoin.pkgs;
secretsDir = config.nix-bitcoin.secretsDir; secretsDir = config.nix-bitcoin.secretsDir;
bitcoind = config.services.bitcoind;
pidFile = "${cfg.dataDir}/liquidd.pid"; pidFile = "${cfg.dataDir}/liquidd.pid";
configFile = pkgs.writeText "elements.conf" '' configFile = pkgs.writeText "elements.conf" ''
chain=${config.services.bitcoind.makeNetworkName "liquidv1" '' chain=${bitcoind.makeNetworkName "liquidv1" ''
regtest regtest
[regtest]'' # Add [regtest] config section [regtest]'' # Add [regtest] config section
} }
@ -166,9 +169,9 @@ 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=${config.services.bitcoind.rpc.address} mainchainrpchost=${bitcoind.rpc.address}
mainchainrpcport=${toString config.services.bitcoind.rpc.port} mainchainrpcport=${toString bitcoind.rpc.port}
mainchainrpcuser=${config.services.bitcoind.rpc.users.public.name} mainchainrpcuser=${bitcoind.rpc.users.public.name}
# Extra config options (from liquidd nixos service) # Extra config options (from liquidd nixos service)
${cfg.extraConfig} ${cfg.extraConfig}

View File

@ -128,6 +128,7 @@ let
runAsUser = config.nix-bitcoin.runAsUserCmd; runAsUser = config.nix-bitcoin.runAsUserCmd;
bitcoind = config.services.bitcoind; bitcoind = config.services.bitcoind;
bitcoindRpcAddress = bitcoind.rpc.address; bitcoindRpcAddress = bitcoind.rpc.address;
networkDir = "${cfg.dataDir}/chain/bitcoin/${bitcoind.network}"; networkDir = "${cfg.dataDir}/chain/bitcoin/${bitcoind.network}";
configFile = pkgs.writeText "lnd.conf" '' configFile = pkgs.writeText "lnd.conf" ''

View File

@ -44,6 +44,8 @@ let
cfg = config.services.spark-wallet; cfg = config.services.spark-wallet;
nbLib = config.nix-bitcoin.lib; nbLib = config.nix-bitcoin.lib;
clightning = config.services.clightning;
# Use wasabi rate provider because the default (bitstamp) doesn't accept # Use wasabi rate provider because the default (bitstamp) doesn't accept
# connections through Tor # connections through Tor
torRateProvider = "--rate-provider wasabi --proxy socks5h://${config.nix-bitcoin.torClientAddressWithPort}"; torRateProvider = "--rate-provider wasabi --proxy socks5h://${config.nix-bitcoin.torClientAddressWithPort}";
@ -52,7 +54,7 @@ let
publicURL="--public-url http://$(${cfg.getPublicAddressCmd})" publicURL="--public-url http://$(${cfg.getPublicAddressCmd})"
''} ''}
exec ${config.nix-bitcoin.pkgs.spark-wallet}/bin/spark-wallet \ 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} \ --host ${cfg.address} --port ${toString cfg.port} \
--config '${config.nix-bitcoin.secretsDir}/spark-wallet-login' \ --config '${config.nix-bitcoin.secretsDir}/spark-wallet-login' \
${optionalString cfg.enforceTor torRateProvider} \ ${optionalString cfg.enforceTor torRateProvider} \
@ -81,7 +83,7 @@ in {
users.users.${cfg.user} = { users.users.${cfg.user} = {
isSystemUser = true; isSystemUser = true;
group = cfg.group; group = cfg.group;
extraGroups = [ config.services.clightning.group ]; extraGroups = [ clightning.group ];
}; };
users.groups.${cfg.group} = {}; users.groups.${cfg.group} = {};