1
e11sync/pkgs/e11sync-static.nix

47 lines
1.0 KiB
Nix
Raw Normal View History

2024-01-14 20:00:17 +02:00
{
stdenv,
runCommand,
2024-01-14 20:00:17 +02:00
python3Packages,
zopfli,
brotli,
findutils,
dart-sass,
2024-01-26 13:48:24 +02:00
jq,
}: let
self = stdenv.mkDerivation {
name = "e11sync-static";
2024-01-26 12:11:37 +02:00
srcs = [../app ../static];
sourceRoot = ".";
nativeBuildInputs = [
python3Packages.django
dart-sass
2024-01-17 12:59:37 +02:00
findutils
];
2024-01-26 12:11:37 +02:00
patchPhase = ''patchShebangs --build app/manage.py'';
buildPhase = ''
2024-01-26 12:11:37 +02:00
make -C static style.css
app/manage.py collectstatic
2024-01-14 20:00:17 +02:00
2024-01-26 13:48:24 +02:00
# remove unversioned files
(cd app/_static;
2024-01-26 17:02:21 +02:00
${jq}/bin/jq -r '.paths | keys[]' staticfiles.json | xargs rm
2024-01-26 13:48:24 +02:00
)
2024-01-26 12:11:37 +02:00
find app/_static \
-name '*.css' -or \
-name '*.js' -or \
2024-01-26 13:48:24 +02:00
-name '*.svg' -or \
-name '*.txt' | \
tee >(xargs -n1 -P''$(nproc) ${zopfli}/bin/zopfli) | \
xargs -n1 -P''$(nproc) ${brotli}/bin/brotli
'';
2024-01-26 12:11:37 +02:00
installPhase = ''mv app/_static $out'';
passthru.manifest = runCommand "e11sync-static-manifest" {} ''
2024-01-26 12:11:37 +02:00
mkdir -p $out
cp ${self}/staticfiles.json $out/
'';
};
in
self