diff --git a/app/signup/migrations/0001_initial.py b/app/signup/migrations/0001_initial.py index 6d66ebf..ab412e6 100644 --- a/app/signup/migrations/0001_initial.py +++ b/app/signup/migrations/0001_initial.py @@ -1,3 +1,4 @@ +# flake8: noqa # Generated by Django 5.0.1 on 2024-01-12 10:04 from django.db import migrations, models diff --git a/flake.nix b/flake.nix index 5001c7f..135f7a2 100644 --- a/flake.nix +++ b/flake.nix @@ -44,7 +44,13 @@ }; in { packages = { - inherit (pkgs) e11sync-static e11sync-caddyfile e11sync-backend; + inherit + (pkgs) + e11sync-static + e11sync-djangostatic + e11sync-caddyfile + e11sync-backend + ; }; checks = { diff --git a/overlay.nix b/overlay.nix index 5645dc2..9dd05f7 100644 --- a/overlay.nix +++ b/overlay.nix @@ -13,6 +13,7 @@ in { inherit geoip2-tarball; }; e11sync-static = withDjango5.callPackage ./pkgs/e11sync-static.nix {}; + e11sync-djangostatic = withDjango5.callPackage ./pkgs/e11sync-djangostatic.nix {}; e11sync-caddyfile = withDjango5.callPackage ./pkgs/e11sync-caddyfile.nix {}; e11sync-backend = withDjango5.callPackage ./pkgs/e11sync-backend.nix {}; }) diff --git a/pkgs/e11sync-backend.nix b/pkgs/e11sync-backend.nix index 697d58f..073dae7 100644 --- a/pkgs/e11sync-backend.nix +++ b/pkgs/e11sync-backend.nix @@ -9,7 +9,7 @@ backendPort ? 8002, databasePath ? null, geoip-mmdb, - e11sync-static, + e11sync-djangostatic, }: let uwsgi-python = uwsgi.override {plugins = ["python3"];}; pythonEnv = python3.withPackages (ps: [ps.django ps.geoip2]); @@ -43,7 +43,7 @@ in ${lib.optionalString (databasePath != null) '' --set E11SYNC_DATABASE_PATH "${databasePath}" \ ''} \ - --set E11SYNC_STATIC_ROOT "${e11sync-static.passthru.manifest}" \ + --set E11SYNC_STATIC_ROOT "${e11sync-djangostatic.passthru.manifest}" \ --set E11SYNC_DEBUG "" \ --set GEOIP_PATH "${geoip-mmdb}" \ ''; @@ -55,7 +55,7 @@ in unpackPhase patchShebangs --build app/manage.py export GEOIP_PATH="${geoip-mmdb}" - export E11SYNC_STATIC_ROOT="${e11sync-static.passthru.manifest}" + export E11SYNC_STATIC_ROOT="${e11sync-djangostatic.passthru.manifest}" app/manage.py test app mkdir -p $out ''; diff --git a/pkgs/e11sync-djangostatic.nix b/pkgs/e11sync-djangostatic.nix new file mode 100644 index 0000000..3742bb7 --- /dev/null +++ b/pkgs/e11sync-djangostatic.nix @@ -0,0 +1,36 @@ +{ + stdenv, + runCommand, + python3Packages, + findutils, + dart-sass, + jq, +}: let + self = stdenv.mkDerivation { + name = "e11sync-djangostatic"; + 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 + pushd app/_static + ${jq}/bin/jq -r '.paths | keys[]' staticfiles.json | xargs rm + popd + ''; + installPhase = ''find; mv app/_static $out''; + + passthru.manifest = runCommand "e11sync-djangostatic-manifest" {} '' + mkdir -p $out + cp ${self}/staticfiles.json $out/ + ''; + }; +in + self diff --git a/pkgs/e11sync-static.nix b/pkgs/e11sync-static.nix index 0c27039..7e0979a 100644 --- a/pkgs/e11sync-static.nix +++ b/pkgs/e11sync-static.nix @@ -1,46 +1,21 @@ { - 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 + e11sync-djangostatic, +}: +runCommand "e11sync-static" { + src = e11sync-djangostatic; + nativeBuildInputs = [findutils]; +} '' + unpackPhase + find e11sync-djangostatic \ + -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 + mv e11sync-djangostatic $out +''