extract variable 'cfg'

This commit is contained in:
Erik Arvstedt 2020-04-07 22:47:42 +02:00
parent 36c84d8360
commit ab617946a9
No known key found for this signature in database
GPG Key ID: 33312B944DD97846

View File

@ -3,6 +3,8 @@
with lib; with lib;
let let
cfg = config.services;
mkHiddenService = map: { mkHiddenService = map: {
map = [ map ]; map = [ map ];
version = 3; version = 3;
@ -46,7 +48,7 @@ in {
enable = true; enable = true;
client.enable = true; client.enable = true;
# LND uses ControlPort to create onion services # LND uses ControlPort to create onion services
controlPort = mkIf config.services.lnd.enable 9051; controlPort = mkIf cfg.lnd.enable 9051;
hiddenServices.sshd = mkHiddenService { port = 22; }; hiddenServices.sshd = mkHiddenService { port = 22; };
}; };
@ -55,9 +57,9 @@ in {
services.bitcoind = { services.bitcoind = {
enable = true; enable = true;
listen = true; listen = true;
sysperms = if config.services.electrs.enable then true else null; sysperms = if cfg.electrs.enable then true else null;
disablewallet = if config.services.electrs.enable then true else null; disablewallet = if cfg.electrs.enable then true else null;
proxy = config.services.tor.client.socksListenAddress; proxy = cfg.tor.client.socksListenAddress;
enforceTor = true; enforceTor = true;
port = 8333; port = 8333;
zmqpubrawblock = "tcp://127.0.0.1:28332"; zmqpubrawblock = "tcp://127.0.0.1:28332";
@ -69,17 +71,17 @@ in {
prune = 0; prune = 0;
dbCache = 1000; dbCache = 1000;
}; };
services.tor.hiddenServices.bitcoind = mkHiddenService { port = config.services.bitcoind.port; }; services.tor.hiddenServices.bitcoind = mkHiddenService { port = cfg.bitcoind.port; };
# clightning # clightning
services.clightning = { services.clightning = {
bitcoin-rpcuser = config.services.bitcoind.rpcuser; bitcoin-rpcuser = cfg.bitcoind.rpcuser;
proxy = config.services.tor.client.socksListenAddress; proxy = cfg.tor.client.socksListenAddress;
enforceTor = true; enforceTor = true;
always-use-proxy = true; always-use-proxy = true;
bind-addr = "127.0.0.1:${toString config.services.clightning.onionport}"; bind-addr = "127.0.0.1:${toString cfg.clightning.onionport}";
}; };
services.tor.hiddenServices.clightning = mkHiddenService { port = config.services.clightning.onionport; }; services.tor.hiddenServices.clightning = mkHiddenService { port = cfg.clightning.onionport; };
# lnd # lnd
services.lnd.enforceTor = true; services.lnd.enforceTor = true;
@ -89,16 +91,16 @@ in {
rpcuser = "liquidrpc"; rpcuser = "liquidrpc";
prune = 1000; prune = 1000;
extraConfig = " extraConfig = "
mainchainrpcuser=${config.services.bitcoind.rpcuser} mainchainrpcuser=${cfg.bitcoind.rpcuser}
mainchainrpcport=8332 mainchainrpcport=8332
"; ";
validatepegin = true; validatepegin = true;
listen = true; listen = true;
proxy = config.services.tor.client.socksListenAddress; proxy = cfg.tor.client.socksListenAddress;
enforceTor = true; enforceTor = true;
port = 7042; port = 7042;
}; };
services.tor.hiddenServices.liquidd = mkHiddenService { port = config.services.liquidd.port; }; services.tor.hiddenServices.liquidd = mkHiddenService { port = cfg.liquidd.port; };
# electrs # electrs
services.electrs = { services.electrs = {
@ -108,8 +110,8 @@ in {
TLSProxy.port = 50003; TLSProxy.port = 50003;
}; };
services.tor.hiddenServices.electrs = mkHiddenService { services.tor.hiddenServices.electrs = mkHiddenService {
port = config.services.electrs.onionport; port = cfg.electrs.onionport;
toPort = config.services.electrs.TLSProxy.port; toPort = cfg.electrs.TLSProxy.port;
}; };
services.spark-wallet.onion-service = true; services.spark-wallet.onion-service = true;
@ -117,43 +119,41 @@ in {
services.nix-bitcoin-webindex.enforceTor = true; services.nix-bitcoin-webindex.enforceTor = true;
environment.systemPackages = with pkgs; with nix-bitcoin; let environment.systemPackages = with pkgs; with nix-bitcoin;
s = config.services;
in
[ [
tor tor
bitcoind bitcoind
(hiPrio s.bitcoind.cli) (hiPrio cfg.bitcoind.cli)
nodeinfo nodeinfo
jq jq
qrencode qrencode
] ]
++ optionals s.clightning.enable [clightning (hiPrio s.clightning.cli)] ++ optionals cfg.clightning.enable [clightning (hiPrio cfg.clightning.cli)]
++ optionals s.lnd.enable [lnd (hiPrio s.lnd.cli)] ++ optionals cfg.lnd.enable [lnd (hiPrio cfg.lnd.cli)]
++ optionals s.lightning-charge.enable [lightning-charge] ++ optionals cfg.lightning-charge.enable [lightning-charge]
++ optionals s.nanopos.enable [nanopos] ++ optionals cfg.nanopos.enable [nanopos]
++ optionals s.nix-bitcoin-webindex.enable [nginx] ++ optionals cfg.nix-bitcoin-webindex.enable [nginx]
++ optionals s.liquidd.enable [elementsd (hiPrio s.liquidd.cli) (hiPrio s.liquidd.swap-cli)] ++ optionals cfg.liquidd.enable [elementsd (hiPrio cfg.liquidd.cli) (hiPrio cfg.liquidd.swap-cli)]
++ optionals s.spark-wallet.enable [spark-wallet] ++ optionals cfg.spark-wallet.enable [spark-wallet]
++ optionals s.electrs.enable [electrs] ++ optionals cfg.electrs.enable [electrs]
++ optionals (s.hardware-wallets.ledger || s.hardware-wallets.trezor) [ ++ optionals (cfg.hardware-wallets.ledger || cfg.hardware-wallets.trezor) [
hwi hwi
# To allow debugging issues with lsusb # To allow debugging issues with lsusb
usbutils usbutils
] ]
++ optionals s.hardware-wallets.trezor [ ++ optionals cfg.hardware-wallets.trezor [
python3.pkgs.trezor python3.pkgs.trezor
]; ];
# Create user operator which can use bitcoin-cli and lightning-cli # Create user operator which can use bitcoin-cli and lightning-cli
users.users.operator = { users.users.operator = {
isNormalUser = true; isNormalUser = true;
extraGroups = [ config.services.bitcoind.group ] extraGroups = [ cfg.bitcoind.group ]
++ (optionals config.services.clightning.enable [ "clightning" ]) ++ (optionals cfg.clightning.enable [ "clightning" ])
++ (optionals config.services.lnd.enable [ "lnd" ]) ++ (optionals cfg.lnd.enable [ "lnd" ])
++ (optionals config.services.liquidd.enable [ config.services.liquidd.group ]) ++ (optionals cfg.liquidd.enable [ cfg.liquidd.group ])
++ (optionals (config.services.hardware-wallets.ledger || config.services.hardware-wallets.trezor) ++ (optionals (cfg.hardware-wallets.ledger || cfg.hardware-wallets.trezor)
[ config.services.hardware-wallets.group ]); [ cfg.hardware-wallets.group ]);
}; };
# Give operator access to onion hostnames # Give operator access to onion hostnames
services.onion-chef.enable = true; services.onion-chef.enable = true;
@ -162,10 +162,10 @@ in {
# Unfortunately c-lightning doesn't allow setting the permissions of the rpc socket # Unfortunately c-lightning doesn't allow setting the permissions of the rpc socket
# https://github.com/ElementsProject/lightning/issues/1366 # https://github.com/ElementsProject/lightning/issues/1366
security.sudo.configFile = security.sudo.configFile =
(optionalString config.services.clightning.enable '' (optionalString cfg.clightning.enable ''
operator ALL=(clightning) NOPASSWD: ALL operator ALL=(clightning) NOPASSWD: ALL
'') + '') +
(optionalString config.services.lnd.enable '' (optionalString cfg.lnd.enable ''
operator ALL=(lnd) NOPASSWD: ALL operator ALL=(lnd) NOPASSWD: ALL
''); '');