1{ config, lib, pkgs, options, type }:
2
3let
4 cfg = config.services.prometheus.exporters."exportarr-${type}";
5 exportarrEnvironment = (
6 lib.mapAttrs (_: toString) cfg.environment
7 ) // {
8 PORT = toString cfg.port;
9 URL = cfg.url;
10 API_KEY_FILE = lib.mkIf (cfg.apiKeyFile != null) "%d/api-key";
11 };
12in
13{
14 port = 9708;
15 extraOpts = {
16 url = lib.mkOption {
17 type = lib.types.str;
18 default = "http://127.0.0.1";
19 description = lib.mdDoc ''
20 The full URL to Sonarr, Radarr, or Lidarr.
21 '';
22 };
23
24 apiKeyFile = lib.mkOption {
25 type = lib.types.nullOr lib.types.path;
26 default = null;
27 description = lib.mdDoc ''
28 File containing the api-key.
29 '';
30 };
31
32 package = lib.mkPackageOptionMD pkgs "exportarr" { };
33
34 environment = lib.mkOption {
35 type = lib.types.attrsOf lib.types.str;
36 default = { };
37 description = lib.mdDoc ''
38 See [the configuration guide](https://github.com/onedr0p/exportarr#configuration) for available options.
39 '';
40 example = {
41 PROWLARR__BACKFILL = true;
42 };
43 };
44 };
45 serviceOpts = {
46 serviceConfig = {
47 LoadCredential = lib.optionalString (cfg.apiKeyFile != null) "api-key:${cfg.apiKeyFile}";
48 ExecStart = ''${cfg.package}/bin/exportarr ${type} "$@"'';
49 ProcSubset = "pid";
50 ProtectProc = "invisible";
51 SystemCallFilter = ["@system-service" "~@privileged"];
52 };
53 environment = exportarrEnvironment;
54 };
55}