onion-services: don't always enable Tor

Previously, Tor was always enabled because `cfg` was always nonempty
(via definitions at `Set sensible defaults for some services`).
Now only enable Tor if there are active onion services.

Also rename var `services` -> `onionServices` to improve readability in
section `Set getPublicAddressCmd ...` where the same name is also used for
option `config.services`.
This commit is contained in:
Erik Arvstedt 2021-10-05 15:07:56 +02:00
parent 3c6a664b7b
commit c8251cdad7
No known key found for this signature in database
GPG Key ID: 33312B944DD97846

View File

@ -43,18 +43,18 @@ let
cfg = config.nix-bitcoin.onionServices;
nbLib = config.nix-bitcoin.lib;
services = builtins.attrNames cfg;
onionServices = builtins.attrNames cfg;
activeServices = builtins.filter (service:
config.services.${service}.enable && cfg.${service}.enable
) services;
) onionServices;
publicServices = builtins.filter (service: cfg.${service}.public) activeServices;
in {
inherit options;
config = mkMerge [
(mkIf (cfg != {}) {
(mkIf (activeServices != []) {
# Define hidden services
services.tor = {
enable = true;
@ -93,7 +93,7 @@ in {
publicServices' = builtins.filter (service:
let srv = cfg.${service};
in srv.public && srv.enable
) services;
) onionServices;
in genAttrs publicServices' (service: {
getPublicAddressCmd = "cat ${config.nix-bitcoin.onionAddresses.dataDir}/services/${service}";
});