{ config, pkgs, lib, ... }: {
  services.nginx.virtualHosts.cinny = {
    listen = [{
      addr = "unix:/run/nginx/cinny.sock";
    }];
    locations."/" = {
      root = pkgs.element-web.override {
        conf = {
          default_server_name = "glia.club";
          default_server_config = {
            m.homeserver = {
              base_url = "https://chat.glia.club";
              server_name = "glia.club";
            };
          };
          disable_custom_urls = false;
          disable_guests = true;
          disable_login_language_selector = false;
          disable_3pid_login = false;
          force_verification = false;
          brand = "Element";
          integrations_ui_url = "https://scalar.vector.im/";
          integrations_rest_url = "https://scalar.vector.im/api";
          integrations_widgets_urls = [
            "https://scalar.vector.im/_matrix/integrations/v1"
            "https://scalar.vector.im/api"
            "https://scalar-staging.vector.im/_matrix/integrations/v1"
            "https://scalar-staging.vector.im/api"
          ];
          default_widget_container_height = 280;
          default_country_code = "GB";
          show_labs_settings = true;
          features = {
            threadsActivityCentre = true;
            feature_video_rooms = true;
            feature_group_calls = true;
            feature_element_call_video_rooms = true;
          };
          default_federate = false;
          default_theme = "light";
          room_directory = {
            servers = ["glia.club"];
          };
          enable_presence_by_hs_url = {
            "https://glia.club" = true;
            "https://chat.glia.club" = true;
            "https://matrix.org" = false;
            "https://matrix-client.matrix.org" = false;
          };
          setting_defaults = {
            breadcrumbs = false;
          };
          jitsi = {
            preferred_domain = "meet.element.io";
          };
          element_call = {
            url = "https://call.element.io";
            brand = "Element Call";
          };
          map_style_url = "https://api.maptiler.com/maps/streets/style.json?key=fU3vlMsMn4Jb6dnEIFsx";
        };
      };
      extraConfig = ''
        index  index.html;

        # Set no-cache for the version, config and index.html
        # so that browsers always check for a new copy of Element Web.
        # NB http://your-domain/ and http://your-domain/? are also covered by this

        location = /index.html {
            add_header Cache-Control "no-cache";
        }
        location = /version {
            add_header Cache-Control "no-cache";
        }
        # covers config.json and config.hostname.json requests as it is prefix.
        location /config {
            add_header Cache-Control "no-cache";
        }
        location /modules/ {
            alias /modules/;
        }
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
      '';
    };
  };
  services.caddy.virtualHosts = {
    "glia.club, glia.club:8448" = {
      extraConfig = lib.mkAfter ''
        reverse_proxy unix//run/nginx/cinny.sock
      '';           
    };

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

}
