about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/exportarr.nix
blob: 8511abbee1bd05391357d60780d66c9c0705ee3f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{ config, lib, pkgs, options, type }:

let
  cfg = config.services.prometheus.exporters."exportarr-${type}";
  exportarrEnvironment = (
    lib.mapAttrs (_: toString) cfg.environment
  ) // {
    PORT = toString cfg.port;
    URL = cfg.url;
    API_KEY_FILE = lib.mkIf (cfg.apiKeyFile != null) "%d/api-key";
  };
in
{
  port = 9708;
  extraOpts = {
    url = lib.mkOption {
      type = lib.types.str;
      default = "http://127.0.0.1";
      description = lib.mdDoc ''
        The full URL to Sonarr, Radarr, or Lidarr.
      '';
    };

    apiKeyFile = lib.mkOption {
      type = lib.types.nullOr lib.types.path;
      default = null;
      description = lib.mdDoc ''
        File containing the api-key.
      '';
    };

    package = lib.mkPackageOption pkgs "exportarr" { };

    environment = lib.mkOption {
      type = lib.types.attrsOf lib.types.str;
      default = { };
      description = lib.mdDoc ''
        See [the configuration guide](https://github.com/onedr0p/exportarr#configuration) for available options.
      '';
      example = {
        PROWLARR__BACKFILL = true;
      };
    };
  };
  serviceOpts = {
    serviceConfig = {
      LoadCredential = lib.optionalString (cfg.apiKeyFile != null) "api-key:${cfg.apiKeyFile}";
      ExecStart = ''${cfg.package}/bin/exportarr ${type} "$@"'';
      ProcSubset = "pid";
      ProtectProc = "invisible";
      SystemCallFilter = ["@system-service" "~@privileged"];
    };
    environment = exportarrEnvironment;
  };
}