about summary refs log tree commit diff
path: root/ops/modules/www/static.tvl.fyi.nix
blob: 7312f78ecf427433e974afb450c770c85ca03b06 (plain) (blame)
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
# Host the static assets at static.tvl.fyi
#
# All assets are served from $base/$drvhash/$file, but can also be
# included with `latest/` which will return a (non-permanent!)
# redirect to the real location.
#
# For all purposes within depot, using the drvhash of web.static is
# recommended.
{ depot, pkgs, ... }:

let staticHash = depot.web.static.drvHash;
in {
  imports = [
    ./base.nix
  ];

  config = {
    services.nginx.virtualHosts."static.tvl.fyi" = {
      serverAliases = [ "static.tvl.su" ];
      enableACME = true;
      forceSSL = true;

      extraConfig = ''
        location = / {
          add_header Content-Type text/plain;
          return 200 "looking for tvl.fyi or tvl.su?";
        }

        location /latest {
          rewrite ^/latest/(.*) /${staticHash}/$1 redirect;
        }

        location /${staticHash}/ {
          alias ${depot.web.static}/;
          expires max;
          add_header Access-Control-Allow-Origin "*";
          add_header Cache-Control "public";
        }
      '';
    };
  };
}