about summary refs log tree commit diff
path: root/modules/piracy/lidarr.nix
blob: a905d8e17657fe152cbcce9d08f11ab255051356 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{
  config,
  inputs,
  lib,
  libNginx,
  this,
  ...
}:
with lib;
let
  cfg = config.nixfiles.modules.piracy.lidarr;

  port = 8686;
in
{
  options.nixfiles.modules.piracy.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:${toString port}" = { };
        virtualHosts.${cfg.domain} = {
          locations."/".proxyPass = "http://lidarr";
          extraConfig = libNginx.config.internalOnly;
        };
      };

      piracy = {
        enable = true;
        jackett.enable = true;
      };
    };

    services = {
      lidarr = {
        enable = true;
        group = "piracy";
      };

      prometheus.exporters.exportarr-lidarr = {
        enable = true;
        url = "http://127.0.0.1";
        port = port + 10000;
        apiKeyFile = config.secrets.lidarr-api-key.path;
        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} - -"
      ];

      services.lidarr.after = [
        "flood.service"
        "jackett.service"
        "local-fs.target"
      ];
    };

    topology = with cfg; {
      nodes.${this.hostname}.services.lidarr = {
        info = domain;
        details.listen.text = "127.0.0.1:${toString port}";
      };
    };
  };
}

Consider giving Nix/NixOS a try! <3