# Dispatcharr — IPTV / M3U / EPG / HDHomeRun-style proxy (Docker, AIO image).
# Docs: https://dispatcharr.github.io/Dispatcharr-Docs/
# Compose reference: https://github.com/Dispatcharr/Dispatcharr/blob/main/docker/docker-compose.aio.yml
#
# Web UI: http://<host>:9191
# After deploy: create an admin user, add playlists / EPG; point Jellyfin at the tuner/M3U URLs
# Dispatcharr shows in its UI.
{ lib, pkgs, ... }:
{
  systemd.tmpfiles.settings."nix-server-dispatcharr-data" = {
    "/var/lib/dispatcharr"."d" = {
      mode = "0755";
      user = "root";
      group = "root";
    };
  };

  systemd.services.docker-dispatcharr.preStart = lib.mkBefore ''
    ${pkgs.coreutils}/bin/mkdir -p /var/lib/dispatcharr
  '';

  virtualisation.oci-containers.containers.dispatcharr = {
    image = "ghcr.io/dispatcharr/dispatcharr:latest";
    ports = [ "9191:9191" ];
    volumes = [
      "/var/lib/dispatcharr:/data"
    ];
    environment = {
      DISPATCHARR_ENV = "aio";
      REDIS_HOST = "localhost";
      CELERY_BROKER_URL = "redis://localhost:6379/0";
      DISPATCHARR_LOG_LEVEL = "info";
      TZ = "America/Moncton";
    };
  };

  networking.firewall.allowedTCPPorts = [ 9191 ];
}
