about summary refs log tree commit diff
path: root/web/static/default.nix
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2021-09-30T22·21+0300
committertazjin <mail@tazj.in>2021-10-01T15·33+0000
commitb1f52b2617902524088e50bf8eff506ba49bb795 (patch)
treed49e7f1081e5999d44fe765eaa828352a838f59b /web/static/default.nix
parent5c9c4aa56625962cf6c61abd069c392415864754 (diff)
feat(web/static): Expose drvHash attribute on derivation r/2943
This can be used for easy cachebusting of static assets, so that we
can serve them all with a really long cache-time easily.

Change-Id: I7c9f6beddec58e1caf02cda33bc587590217a939
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3660
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'web/static/default.nix')
-rw-r--r--web/static/default.nix14
1 files changed, 10 insertions, 4 deletions
diff --git a/web/static/default.nix b/web/static/default.nix
index 518f21d6f91c..ef346f9c746f 100644
--- a/web/static/default.nix
+++ b/web/static/default.nix
@@ -1,6 +1,12 @@
-{ pkgs, ... }:
+# Expose all static assets as a folder. The derivation contains a
+# `drvHash` attribute which can be used for cache-busting.
+{ depot, lib, pkgs, ... }:
 
-# Needs to be a derivation ...
-pkgs.runCommand "tvl-static" {} ''
+let storeDirLength = with builtins; (stringLength storeDir) + 1;
+in lib.fix(self: pkgs.runCommand "tvl-static" {
+  passthru = {
+    drvHash = lib.substring storeDirLength 32 self.drvPath;
+  };
+} ''
   cp -r ${./.} $out
-''
+'')