summaryrefslogtreecommitdiff
path: root/nixos/sites/default.nix
blob: b78d571ec5eced57f351dabeabfc4e4a8140f792 (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
44
45
{ pkgs, ... }:

{
  catbus-web-ui = pkgs.callPackage ./catbus-web-ui.nix {};
  cgit          = pkgs.callPackage ./cgit.nix {};
  go-packages   = pkgs.callPackage ./go-packages.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}";
      };
    };
  };
}