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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{ depot, pkgs, lib, config, ... }:

let
  cfg = config.profpatsch.decentsoftware;

  www = pkgs.runCommandLocal "decentsoftware-www" {} ''
    mkdir $out
    cp ${./static/index.html} $out/index.html
    cp ${./static/warcry.txt} $out/warcry.txt
  '';

in {
  options.profpatsch.decentsoftware = {
    enable = lib.mkEnableOption "decentsoftwa.re website";
  };

  config = lib.mkIf cfg.enable {

    services.nginx.virtualHosts."decentsoftwa.re" = {
      forceSSL = true;
      enableACME = true;
      locations."/".root = www;

      locations."/.well-known/matrix/".root = pkgs.linkFarm "well-known-decentsoftwa.re-matrix" [
        { name = ".well-known/matrix/server";
          path = pkgs.writers.writeJSON "matrix-server-well-known" {
            "m.server" = "matrix.decentsoftwa.re:443";
          };
        }
      ];

      # account.conversations.im XMPP certificate signature
      locations."/.well-known/posh".root = pkgs.linkFarm "well-known-xmpp-client-thingy" [
        { name = ".well-known/posh/xmpp-client.json";
          path = pkgs.writers.writeJSON "conversations.im-xmpp-client.json" {
            fingerprints = [ { "sha-256" = "pSWZpTkHmNZdGk6CjsaNXXexlCAu+NcXg8MIzUB8tbU="; } ];
            "expires" = 3600;
          };
        }
      ];

      # make XMPP clients know about the conversations.im BOSH endpoint
      locations."/.well-known/host-meta" = {
        proxyPass = "https://conversations.im/.well-known/host-meta";
        # https://jsxc.readthedocs.io/en/latest/getting-started/requirements.html#nginx
        extraConfig = ''
          proxy_set_header Host $proxy_host;
          tcp_nodelay on;
        '';
      };
    };

  };
}