{ config, pkgs, lib, ... }: {
  services.nginx.virtualHosts.cinny = {
    listen = [{
      addr = "unix:/run/nginx/cinny.sock";
    }];
    locations."/" = {
      root = pkgs.cinny.override {
        conf = {
          defaultHomeserver = 0;
          homeserverList = [
            "glia.club"
          ];
          allowCustomHomeservers = false;

          featuredCommunities = {
            openAsDefault = false;
            spaces = [
            ];
            rooms = [
            ];
            servers = [
            ];
          };

          hashRouter = {
            enabled = false;
            basename = "/";
          };
        };
      };
      extraConfig = ''
        rewrite ^/config.json$ /config.json break;
        rewrite ^/manifest.json$ /manifest.json break;

        rewrite ^/sw.js$ /sw.js break;
        rewrite ^/pdf.worker.min.js$ /pdf.worker.min.js break;

        rewrite ^/public/(.*)$ /public/$1 break;
        rewrite ^/assets/(.*)$ /assets/$1 break;

        rewrite ^(.+)$ /index.html break;
      '';
    };
  };
  services.caddy.virtualHosts = {
    "glia.club, glia.club:8448" = {
      extraConfig = lib.mkAfter ''
        redir https://chat.glia.club
      '';           
    };

    "chat.glia.club" = {
      extraConfig = ''
        reverse_proxy unix//run/nginx/cinny.sock
      '';
    };
  };

}
