aboutsummaryrefslogtreecommitdiff
path: root/modules/nixosModules/watcharr.nix
blob: 2263e4f94d225c6ec6b35f2630f97d630becff3b (plain)
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
{
  inputs,
  self,
  ...
}: {
  flake.nixosModules.watcharr = {
    config,
    lib,
    pkgs,
    ...
  }:
    with lib; let
      cfg = config.services.watcharr;
      port = builtins.toString cfg.settings.port;
    in {
      options = {
        services.watcharr = {
          enable = mkEnableOption "Enable watcharr service";
          subdomain = mkOption {
            type = types.str;
            description = ''
              Subdomain to use for nginx.
            '';
          };
          settings = {
            dataDir = mkOption {
              type = types.path;
              description = ''
                Watcharr data directory.
              '';
              default = "/var/lib/watcharr";
            };
            port = mkOption {
              type = types.port;
              default = 3080;
              description = ''
                Port to use.
              '';
            };
          };
        };
      };

      config = mkIf cfg.enable {
        createPaths = {
          "${cfg.settings.dataDir}" = {
            owner = "root";
            group = "root";
            permissions = "0750";
          };
        };

        nginxProxy = {
          enable = true;
          subdomains = {
            "${cfg.subdomain}" = {
              proxyPass = "http://127.0.0.1:${port}";
              proxyWebsockets = true;
            };
          };
        };

        virtualisation.oci-containers.containers.watcharr = {
          image = "ghcr.io/sbondco/watcharr:latest";
          ports = [
            "127.0.0.1${port}:3080"
          ];
          volumes = [
            "${cfg.settings.dataDir}:/data"
          ];
        };
      };
    };
}