1{ config, lib, pkgs, options }: 2 3let 4 inherit (lib) mkOption types; 5 cfg = config.services.prometheus.exporters.sabnzbd; 6in 7{ 8 port = 9387; 9 10 extraOpts = { 11 servers = mkOption { 12 description = "List of sabnzbd servers to connect to."; 13 type = types.listOf (types.submodule { 14 options = { 15 baseUrl = mkOption { 16 type = types.str; 17 description = "Base URL of the sabnzbd server."; 18 example = "http://localhost:8080/sabnzbd"; 19 }; 20 apiKeyFile = mkOption { 21 type = types.str; 22 description = "File containing the API key."; 23 example = "/run/secrets/sabnzbd_apikey"; 24 }; 25 }; 26 }); 27 }; 28 }; 29 30 serviceOpts = 31 let 32 servers = lib.zipAttrs cfg.servers; 33 apiKeys = lib.concatStringsSep "," (builtins.map (file: "$(cat ${file})") servers.apiKeyFile); 34 in 35 { 36 environment = { 37 METRICS_PORT = toString cfg.port; 38 METRICS_ADDR = cfg.listenAddress; 39 SABNZBD_BASEURLS = lib.concatStringsSep "," servers.baseUrl; 40 }; 41 42 script = '' 43 export SABNZBD_APIKEYS="${apiKeys}" 44 exec ${lib.getExe pkgs.prometheus-sabnzbd-exporter} 45 ''; 46 }; 47}