From 58d5c8a812a94d8929ea32628b889f3492525134 Mon Sep 17 00:00:00 2001 From: pazpi Date: Tue, 10 Sep 2024 19:50:31 +0200 Subject: [PATCH] Renamed module with a proper name --- modules/services/default.nix | 2 +- modules/services/download-pod.nix | 172 ------------------- modules/services/media-mgr.nix | 263 ++++++++++++++++++++++++++++++ 3 files changed, 264 insertions(+), 173 deletions(-) delete mode 100644 modules/services/download-pod.nix create mode 100644 modules/services/media-mgr.nix diff --git a/modules/services/default.nix b/modules/services/default.nix index 87b15f9..fcdf778 100644 --- a/modules/services/default.nix +++ b/modules/services/default.nix @@ -1,6 +1,6 @@ { imports = [ - ./download-pod.nix + ./media-mgr.nix ./nextcloud-podman.nix ]; } diff --git a/modules/services/download-pod.nix b/modules/services/download-pod.nix deleted file mode 100644 index 3a8a825..0000000 --- a/modules/services/download-pod.nix +++ /dev/null @@ -1,172 +0,0 @@ -{ - config, - pkgs, - lib, - ... -}: - -with lib; - -let - cfg = config.my.services.download-pod; - - containersDefinition = { - - jackett = { - enable = true; - image = "linuxserver/jackett"; - autoStart = true; - volumes = [ - "jackett_config:/config" - "jackett_data:/data" - ]; - }; - - radarr = { - enable = true; - image = "linuxserver/radarr"; - autoStart = true; - volumes = [ - "radarr_config:/config" - "radarr_data:/data" - ]; - }; - - sonarr = { - enable = true; - image = "linuxserver/sonarr"; - autoStart = true; - volumes = [ - "sonarr_config:/config" - "sonarr_data:/data" - ]; - }; - - prowlarr = { - enable = true; - image = "linuxserver/prowlarr"; - autoStart = true; - volumes = [ "prowlarr_config:/config" ]; - }; - }; - - # Pod Definition - podDefinition = { - name = "download"; - ports = [ - "7878:7878" # : Radarr - "8989:8989" # : Sonarr - "9117:9117" # : Jackett - "9696:9696" # : Prowlarr - ]; - containers = containersDefinition; - }; - -in -{ - options.my.services.download-pod = { - - programs = { - enable = lib.mkEnableOption "Enable the download search stack"; - }; - - proxy = { - enable = lib.mkEnableOption "Enable proxy for the services"; - - hostName = lib.mkOption { - default = "example.com"; - type = lib.types.str; - description = '' - Top level hostname - ''; - }; - - serverName = lib.mkOption { - default = "localhost"; - type = lib.types.str; - description = '' - Server name where Caddy is - ''; - }; - - }; - - }; - - config = lib.mkMerge [ - - # Services definition - (lib.mkIf cfg.programs.enable { - - services = { - - # Indexer - prowlarr = { - enable = true; - openFirewall = true; - }; - - # Movies - radarr = { - enable = true; - openFirewall = true; - }; - - # TV Shows - sonarr = { - enable = true; - openFirewall = true; - }; - - # Music - lidarr = { - enable = true; - openFirewall = true; - }; - - # E-books - readarr = { - enable = true; - openFirewall = true; - }; - - }; - - # my.virtualisation.podmanPods = { - # inherit podDefinition; - # }; - - # virtualisation.oci-containers.containers = - # let - # pod = config.helpers.processContainers podDefinition; - # in - # pod.containers; - - }) - - # Caddy for reverse proxy - (lib.mkIf cfg.proxy.enable { - - services.caddy = { - enable = true; - package = pkgs.caddy-custom; - # {env.CLOUDFLARE_KEY} - extraConfig = '' - (cloudflare) { - tls { - dns cloudflare {env.CLOUDFLARE_KEY} - } - } - ''; - virtualHosts."prowlarr.tegola.pro".extraConfig = '' - reverse_proxy http://arr.internal:9696 - import cloudflare - ''; - virtualHosts."radarr.tegola.pro".extraConfig = '' - reverse_proxy http://arr.internal:7878 - import cloudflare - ''; - }; - }) - ]; -} diff --git a/modules/services/media-mgr.nix b/modules/services/media-mgr.nix new file mode 100644 index 0000000..08ed7ea --- /dev/null +++ b/modules/services/media-mgr.nix @@ -0,0 +1,263 @@ +{ config +, pkgs +, lib +, ... +}: + +with lib; + +let + cfg = config.my.services.media-mgr; + + containersDefinition = { + + jackett = { + enable = true; + image = "linuxserver/jackett"; + autoStart = true; + volumes = [ + "jackett_config:/config" + "jackett_data:/data" + ]; + }; + + radarr = { + enable = true; + image = "linuxserver/radarr"; + autoStart = true; + volumes = [ + "radarr_config:/config" + "radarr_data:/data" + ]; + }; + + sonarr = { + enable = true; + image = "linuxserver/sonarr"; + autoStart = true; + volumes = [ + "sonarr_config:/config" + "sonarr_data:/data" + ]; + }; + + prowlarr = { + enable = true; + image = "linuxserver/prowlarr"; + autoStart = true; + volumes = [ "prowlarr_config:/config" ]; + }; + }; + + # Pod Definition + podDefinition = { + name = "download"; + ports = [ + "7878:7878" # : Radarr + "8989:8989" # : Sonarr + "9117:9117" # : Jackett + "9696:9696" # : Prowlarr + ]; + containers = containersDefinition; + }; + +in +{ + options.my.services.media-mgr = { + + programs = { + enable = lib.mkEnableOption "Enable the download manager stack"; + }; + + exportMetrics = { + enable = lib.mkEnableOption "Enable monitoring for the download manager stack"; + }; + + proxy = { + enable = lib.mkEnableOption "Set the proxy entry for this service"; + + domain = lib.mkOption { + default = "example.com"; + type = lib.types.str; + description = '' + The domain where Caddy is reachable + ''; + }; + + host = lib.mkOption { + default = "localhost"; + type = lib.types.str; + description = '' + host name where the download manager stack is running + ''; + }; + + }; + + }; + + config = lib.mkMerge [ + + # Services definition + (lib.mkIf cfg.programs.enable { + + services = { + + # Indexer + prowlarr = { + enable = true; + openFirewall = true; + }; + + # Movies + radarr = { + enable = true; + openFirewall = true; + }; + + # TV Shows + sonarr = { + enable = true; + openFirewall = true; + }; + + # Music + lidarr = { + enable = true; + openFirewall = true; + }; + + # E-books + readarr = { + enable = true; + openFirewall = true; + }; + + }; + + # my.virtualisation.podmanPods = { + # inherit podDefinition; + # }; + + # virtualisation.oci-containers.containers = + # let + # pod = config.helpers.processContainers podDefinition; + # in + # pod.containers; + + }) + + # Caddy for reverse proxy + (lib.mkIf cfg.proxy.enable { + services.caddy = with cfg.proxy; { + virtualHosts."prowlarr.${domain}".extraConfig = '' + reverse_proxy http://${host}:9696 + import cloudflare + ''; + virtualHosts."radarr.${domain}".extraConfig = '' + reverse_proxy http://${host}:7878 + import cloudflare + ''; + virtualHosts."sonarr.${domain}".extraConfig = '' + reverse_proxy http://${host}:8989 + import cloudflare + ''; + virtualHosts."lidarr.${domain}".extraConfig = '' + reverse_proxy http://${host}:8686 + import cloudflare + ''; + virtualHosts."readarr.${domain}".extraConfig = '' + reverse_proxy http://${host}:8787 + import cloudflare + ''; + }; + }) + + # Prometheus exporters + (lib.mkIf cfg.exportMetrics.enable { + + users.groups.exportarr = { }; + users.users.exportarr = { + group = "exportarr"; + isSystemUser = true; + }; + + age.secrets = { + prowlarr-apiKey = { + file = ../../secrets/prowlarr-apiKey.age; + owner = "exportarr"; + group = "exportarr"; + mode = "770"; + }; + }; + age.secrets = { + radarr-apiKey = { + file = ../../secrets/radarr-apiKey.age; + owner = "exportarr"; + group = "exportarr"; + mode = "770"; + }; + }; + age.secrets = { + sonarr-apiKey = { + file = ../../secrets/sonarr-apiKey.age; + owner = "exportarr"; + group = "exportarr"; + mode = "770"; + }; + }; + age.secrets = { + lidarr-apiKey = { + file = ../../secrets/lidarr-apiKey.age; + owner = "exportarr"; + group = "exportarr"; + mode = "770"; + }; + }; + age.secrets = { + readarr-apiKey = { + file = ../../secrets/readarr-apiKey.age; + owner = "exportarr"; + group = "exportarr"; + mode = "770"; + }; + }; + + services.prometheus.exporters = { + exportarr-prowlarr = { + enable = true; + url = "http://arr.internal:9696"; + port = 9701; + apiKeyFile = config.age.secrets.prowlarr-apiKey.path; + }; + exportarr-radarr = { + enable = true; + url = "http://arr.internal:7878"; + port = 9702; + user = "exportarr"; + group = "exportarr"; + apiKeyFile = config.age.secrets.radarr-apiKey.path; + }; + exportarr-sonarr = { + enable = true; + url = "http://arr.internal:8989"; + port = 9703; + apiKeyFile = config.age.secrets.sonarr-apiKey.path; + }; + exportarr-lidarr = { + enable = true; + url = "http://arr.internal:8686"; + port = 9704; + apiKeyFile = config.age.secrets.lidarr-apiKey.path; + }; + exportarr-readarr = { + enable = true; + url = "http://arr.internal:8787"; + port = 9705; + apiKeyFile = config.age.secrets.readarr-apiKey.path; + }; + }; + }) + + ]; +}