1
e11sync/pkgs/e11sync-static.nix
2024-01-26 17:05:31 +02:00

47 lines
1.0 KiB
Nix

{
stdenv,
runCommand,
python3Packages,
zopfli,
brotli,
findutils,
dart-sass,
jq,
}: let
self = stdenv.mkDerivation {
name = "e11sync-static";
srcs = [../app ../static];
sourceRoot = ".";
nativeBuildInputs = [
python3Packages.django
dart-sass
findutils
];
patchPhase = ''patchShebangs --build app/manage.py'';
buildPhase = ''
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' -or \
-name '*.txt' | \
tee >(xargs -n1 -P''$(nproc) ${zopfli}/bin/zopfli) | \
xargs -n1 -P''$(nproc) ${brotli}/bin/brotli
'';
installPhase = ''mv app/_static $out'';
passthru.manifest = runCommand "e11sync-static-manifest" {} ''
mkdir -p $out
cp ${self}/staticfiles.json $out/
'';
};
in
self