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