summaryrefslogtreecommitdiff
path: root/nixos/hosts/tente/web-personal.nix
blob: 7c170630ea151898a482a10e72e492ec38163e1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{ config, lib, pkgs, ... }:

let
  cfg = config.web-personal;
in
{
  options.web-personal = {
    domain = lib.mkOption {
      type = lib.types.str;
    };
    matrixApiDomain = lib.mkOption {
      type = lib.types.str;
    };
  };

  config = {
    services = {
      nginx.virtualHosts.${cfg.domain} =
        let
          mkWellKnown = data: ''
            default_type application/json;
            add_header Access-Control-Allow-Origin *;
            return 200 '${builtins.toJSON data}';
          '';
        in
        {
          enableACME = true;
          forceSSL = true;
          root = "/srv/www/${cfg.domain}";

          locations."= /.well-known/matrix/server".extraConfig = mkWellKnown {
            "m.server" = "${cfg.matrixApiDomain}:443";
          };
          locations."= /.well-known/matrix/client".extraConfig = mkWellKnown {
            "m.homeserver" = { base_url = "https://${cfg.matrixApiDomain}"; };
          };
        };
    };
  };
}