{ lib, ... }:

let
  domain = "htnzb.giugl.io";
  network = import ./network.nix;
  auth_block = (import ./openid.nix { inherit lib; }).openresty_oidc_block;
in
{
  services = {
    nzbget = {
      enable = true;
      group = "media";
    };

    nginx.virtualHosts.${domain} = {
      forceSSL = true;
      enableACME = true;
      locations."/" = {
        proxyPass = "http://127.0.0.1:6789";
        extraConfig = auth_block {
          access_role = "nzbget";
        };
      };
    };
  };

  networking.extraHosts = ''
    ${network.architect-lan} ${domain}
    ${network.architect-wg} ${domain}
    ${network.architect-ts} ${domain}
  '';

  users.groups.media.members = [ "nzbget" ];
}