summaryrefslogtreecommitdiff
path: root/nixos/sites/default.nix
blob: 032803e5a54b250cc1e84abfec37c971d8a1151a (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
41
42
43
{ pkgs, ... }:

{
  catbus-web-ui = pkgs.callPackage ./catbus-web-ui.nix {};

  https = site: site // {
    forceSSL = true;
    enableACME = true;
  };

  static = root: {
    locations = {
      "/" = {
        root = root;
        extraConfig = ''
          if ($request_uri ~ ^/(.*)\.html$) {
            return 302 /$1;
          }
          if ($request_uri ~ ^/(.*)/$) {
            return 302 /$1;
          }
          try_files $uri $uri.$extension $uri/ =404;
        '';
      };
    };
  };

  proxyACME = remoteHost: {
    locations = {
      "/.well-known/acme-challenge/" = {
        proxyPass = "http://${remoteHost}";
      };
    };
  };

  proxySocket = socketPath: {
    locations = {
      "/" = {
        proxyPass = "http://unix:/${socketPath}";
      };
    };
  };
}