about summary refs log tree commit diff
path: root/modules/nixos/lidarr.nix
blob: 84d363bae8040379e4655b57eff5553bf9483c4e (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
56
57
58
59
60
{
  config,
  inputs,
  lib,
  libNginx,
  ...
}:
with lib;
let
  cfg = config.nixfiles.modules.lidarr;
in
{
  options.nixfiles.modules.lidarr = {
    enable = mkEnableOption "Lidarr";

    domain = mkOption {
      description = "Domain name sans protocol scheme.";
      type = with types; str;
      default = "lidarr.${config.networking.domain}";
    };
  };

  config = mkIf cfg.enable {
    secrets.lidarr-api-key.file = "${inputs.self}/secrets/lidarr-api-key";

    ark.directories = [ "/var/lib/lidarr" ];

    nixfiles.modules.nginx = {
      enable = true;
      upstreams.lidarr.servers."127.0.0.1:8686" = { };
      virtualHosts.${cfg.domain} = {
        locations."/".proxyPass = "http://lidarr";
        extraConfig = libNginx.config.internalOnly;
      };
    };

    services = {
      lidarr = {
        enable = true;
        user = "rtorrent";
        group = "rtorrent";
      };

      prometheus.exporters.exportarr-lidarr = {
        enable = true;
        url = "http://127.0.0.1";
        apiKeyFile = config.secrets.lidarr-api-key.path;
        port = mkDefault 9708;
        inherit (config.services.lidarr) user;
        inherit (config.services.lidarr) group;
        listenAddress = this.wireguard.ipv4.address;
        environment.CONFIG = "/var/lib/lidarr/.config/Lidarr/config.xml";
      };
    };

    systemd.tmpfiles.rules = with config.services.lidarr; [
      "d /var/lib/lidarr/root 0755 ${user} ${group} - -"
    ];
  };
}

Consider giving Nix/NixOS a try! <3