2024-01-14 19:54:32 +02:00
|
|
|
{
|
2024-01-14 23:23:39 +02:00
|
|
|
lib,
|
2024-01-14 19:54:32 +02:00
|
|
|
stdenv,
|
|
|
|
runCommand,
|
|
|
|
makeWrapper,
|
2024-01-16 00:09:47 +02:00
|
|
|
python3,
|
2024-01-14 19:54:32 +02:00
|
|
|
libmaxminddb,
|
2024-01-15 16:14:46 +02:00
|
|
|
uwsgi,
|
|
|
|
backendPort ? 8002,
|
2024-01-16 15:38:00 +02:00
|
|
|
databasePath ? null,
|
2024-01-15 10:52:46 +02:00
|
|
|
geoip-mmdb,
|
2024-01-28 16:42:17 +02:00
|
|
|
e11sync-djangostatic,
|
2024-01-16 13:31:28 +02:00
|
|
|
}: let
|
|
|
|
uwsgi-python = uwsgi.override {plugins = ["python3"];};
|
2024-01-26 17:02:21 +02:00
|
|
|
pythonEnv = python3.withPackages (ps: [ps.django ps.geoip2]);
|
2024-01-16 13:31:28 +02:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "e11sync-backend";
|
|
|
|
propagatedBuildInputs = [
|
2024-01-16 23:18:51 +02:00
|
|
|
pythonEnv
|
2024-01-16 13:31:28 +02:00
|
|
|
libmaxminddb
|
|
|
|
];
|
|
|
|
nativeBuildInputs = [makeWrapper];
|
|
|
|
src = ../app;
|
|
|
|
patchPhase = ''patchShebangs --build manage.py'';
|
|
|
|
buildPhase = ''mkdir -p $out'';
|
|
|
|
installPhase = ''
|
|
|
|
cp -r . $out/app
|
|
|
|
makeWrapper $out/app/manage.py $out/bin/e11sync \
|
2024-01-16 22:59:18 +02:00
|
|
|
${lib.optionalString (databasePath != null) ''
|
|
|
|
--set E11SYNC_DATABASE_PATH "${databasePath}" \
|
|
|
|
''} \
|
2024-01-16 13:31:28 +02:00
|
|
|
--set GEOIP_PATH "${geoip-mmdb}"
|
2024-01-15 16:14:46 +02:00
|
|
|
|
2024-01-16 13:31:28 +02:00
|
|
|
makeWrapper ${uwsgi-python}/bin/uwsgi $out/bin/e11sync-backend \
|
|
|
|
--chdir $out/app \
|
|
|
|
--set-default E11SYNC_HTTP_PORT ${toString backendPort} \
|
2024-01-16 23:39:50 +02:00
|
|
|
--add-flags "--need-plugin ${uwsgi-python}/lib/uwsgi/python3_plugin.so" \
|
2024-01-16 23:18:51 +02:00
|
|
|
--add-flags "--python-path ${pythonEnv}/lib/${pythonEnv.libPrefix}/site-packages" \
|
2024-01-16 13:31:28 +02:00
|
|
|
--add-flags "--http-socket 127.0.0.1:${toString backendPort}" \
|
|
|
|
--add-flags "--wsgi-file e11sync/wsgi.py" \
|
2024-01-16 23:39:50 +02:00
|
|
|
--add-flags "--master --need-app" \
|
2024-01-16 15:38:00 +02:00
|
|
|
${lib.optionalString (databasePath != null) ''
|
|
|
|
--set E11SYNC_DATABASE_PATH "${databasePath}" \
|
2024-01-16 13:31:28 +02:00
|
|
|
''} \
|
2024-01-28 16:42:17 +02:00
|
|
|
--set E11SYNC_STATIC_ROOT "${e11sync-djangostatic.passthru.manifest}" \
|
2024-01-16 23:31:21 +02:00
|
|
|
--set E11SYNC_DEBUG "" \
|
2024-01-16 13:31:28 +02:00
|
|
|
--set GEOIP_PATH "${geoip-mmdb}" \
|
2024-01-14 23:31:23 +02:00
|
|
|
'';
|
2024-01-16 13:31:28 +02:00
|
|
|
passthru.tests.unit =
|
|
|
|
runCommand "e11sync-test" {
|
2024-01-26 12:11:37 +02:00
|
|
|
srcs = ../app;
|
2024-01-26 17:02:21 +02:00
|
|
|
buildInputs = [pythonEnv];
|
2024-01-16 13:31:28 +02:00
|
|
|
} ''
|
|
|
|
unpackPhase
|
|
|
|
patchShebangs --build app/manage.py
|
|
|
|
export GEOIP_PATH="${geoip-mmdb}"
|
2024-01-28 16:42:17 +02:00
|
|
|
export E11SYNC_STATIC_ROOT="${e11sync-djangostatic.passthru.manifest}"
|
2024-01-16 13:31:28 +02:00
|
|
|
app/manage.py test app
|
|
|
|
mkdir -p $out
|
|
|
|
'';
|
|
|
|
}
|