1 { config, lib, pkgs, options, ... }:
4 inherit (lib) mkOption types;
5 cfg = config.services.prometheus.exporters.sabnzbd;
12 description = "List of sabnzbd servers to connect to.";
13 type = types.listOf (types.submodule {
17 description = "Base URL of the sabnzbd server.";
18 example = "http://localhost:8080/sabnzbd";
20 apiKeyFile = mkOption {
23 The path to a file containing the API key.
24 The file is securely passed to the service by leveraging systemd credentials.
25 No special permissions need to be set on this file.
27 example = "/run/secrets/sabnzbd_apikey";
36 servers = lib.zipAttrs cfg.servers;
37 credentials = lib.imap0 (i: v: { name = "apikey-${toString i}"; path = v; }) servers.apiKeyFile;
40 serviceConfig.LoadCredential = builtins.map ({ name, path }: "${name}:${path}") credentials;
43 METRICS_PORT = toString cfg.port;
44 METRICS_ADDR = cfg.listenAddress;
45 SABNZBD_BASEURLS = lib.concatStringsSep "," servers.baseUrl;
50 apiKeys = lib.concatStringsSep "," (builtins.map (cred: "$(< $CREDENTIALS_DIRECTORY/${cred.name})") credentials);
53 export SABNZBD_APIKEYS="${apiKeys}"
54 exec ${lib.getExe pkgs.prometheus-sabnzbd-exporter}