From d54da85c56771fa5fde57e1d49a421d1ebbff97d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Fri, 26 Jan 2024 13:48:24 +0200 Subject: [PATCH] e11sync-static: fix caching --- pkgs/e11sync-caddyfile.nix | 2 +- pkgs/e11sync-static.nix | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkgs/e11sync-caddyfile.nix b/pkgs/e11sync-caddyfile.nix index 0740102..ad8d7c1 100644 --- a/pkgs/e11sync-caddyfile.nix +++ b/pkgs/e11sync-caddyfile.nix @@ -6,7 +6,7 @@ writeTextFile { name = "e11sync-caddyfile"; text = '' - header /static/CACHE/* Cache-Control "public, max-age=31536000, immutable" + header /static/* Cache-Control "public, max-age=31536000, immutable" route /static/* { uri strip_prefix /static diff --git a/pkgs/e11sync-static.nix b/pkgs/e11sync-static.nix index de80b6f..dba56a6 100644 --- a/pkgs/e11sync-static.nix +++ b/pkgs/e11sync-static.nix @@ -6,6 +6,7 @@ brotli, findutils, dart-sass, + jq, }: let self = stdenv.mkDerivation { name = "e11sync-static"; @@ -18,14 +19,20 @@ ]; patchPhase = ''patchShebangs --build app/manage.py''; buildPhase = '' - export E11SYNC_DEBUG= make -C static style.css app/manage.py collectstatic + # remove unversioned files + (cd app/_static; + ${jq}/bin/jq -r '.paths | keys[]' staticfiles.json | \ + xargs rm + ) + find app/_static \ -name '*.css' -or \ -name '*.js' -or \ - -name '*.svg' | \ + -name '*.svg' -or \ + -name '*.txt' | \ tee >(xargs -n1 -P''$(nproc) ${zopfli}/bin/zopfli) | \ xargs -n1 -P''$(nproc) ${brotli}/bin/brotli '';