The setup is explained in the comment, but TL;DR: Use the derivation hash of static files to create permanent URLs. Relates to b/151. Change-Id: Ib1ca3a1a00c90a47f4bf39c29a8b4bbf5b215e7d Reviewed-on: https://cl.tvl.fyi/c/depot/+/3664 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
		
			
				
	
	
		
			42 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
| # 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";
 | |
|         }
 | |
|       '';
 | |
|     };
 | |
|   };
 | |
| }
 |