{ self }:
{ config, pkgs, ... }:

{
  services.nginx = {
    enable = true;

    virtualHosts."erambler.co.uk" = {
      enableACME = true;
      forceSSL = true;

      # root = self.defaultPackage.${pkgs.system};
      root = "/srv/www/erambler.co.uk";
      extraConfig = ''
        rewrite ^/.well-known/(host-meta|webfinger).* https://fed.brid.gy$request_uri redirect;
      '';
      locations = {
        "~ ^/(feed|rss)(\\.xml|/)".return = "301 /index.xml";
        "~ ^/tags/([a-zA-Z-]+)\\.xml".return = "301 /tags/$1/index.xml";

        "/index.xml".extraConfig = ''
          add_header Link '<https://erambler.co.uk/rss.xml>; rel="self"';
        '';
      };
    };
  };

  networking.firewall.allowedTCPPorts = [ 80 443 ];
}
