{ pkgs
, config
, ...}: {
  services.jellyfin = {
    enable = true;
    openFirewall = true;
    dataDir = "/nix/persist/service/jellyfin";
  };

  environment.systemPackages = with pkgs; [ jellyfin jellyfin-web jellyfin-ffmpeg ];

  users.users.jellyfin.uid = 282;
  users.groups.jellyfin.gid = 282;

  services.nginx.virtualHosts."jellyfin.514fpv.io" = {
    useACMEHost = ".514fpv.io";
    addSSL = true;
    locations = {
      "= /".return = "302 https://jellyfin.514fpv.io:2096/web/";
      "/" = {
        proxyPass = "http://127.0.0.1:8096";
        extraConfig = ''
          proxy_buffering off;
        '';
      };
      "= /web/".proxyPass = "http://127.0.0.1:8096/web/index.html";
      "/socket" = {
        proxyPass = "http://127.0.0.1:8096";
        proxyWebsockets = true;
      };
    };
  };

  global.fs.zfs.mountpoints."/nix/persist/service/jellyfin" = "service/jellyfin";
}
