1

e11sync: move to it's own package

This commit is contained in:
Motiejus Jakštys 2024-01-14 19:54:32 +02:00
parent 96181f5075
commit 6499795df1
2 changed files with 63 additions and 39 deletions

View File

@ -30,16 +30,14 @@
... ...
}: }:
flake-utils.lib.eachDefaultSystem (system: let flake-utils.lib.eachDefaultSystem (system: let
gunicornPort = 8001;
pkgs = import nixpkgs {inherit system;}; pkgs = import nixpkgs {inherit system;};
appDeps = with pkgs.python3Packages; [django_5 django-compressor]; appDeps = with pkgs.python3Packages; [django_5 django-compressor];
runtimeDeps = with pkgs; appDeps ++ [python3Packages.geoip2 libmaxminddb]; runtimeDeps = with pkgs; appDeps ++ [python3Packages.geoip2 libmaxminddb];
buildDeps = with pkgs; appDeps ++ [dart-sass]; buildDeps = with pkgs; appDeps ++ [dart-sass];
geoip = pkgs.stdenv.mkDerivation { geoip-archive = pkgs.stdenv.mkDerivation {
name = "geoip"; name = "geoip-archive";
srcs = [geoip2-asn geoip2-city geoip2-country]; srcs = [geoip2-asn geoip2-city geoip2-country];
dontUnpack = true; dontUnpack = true;
installPhase = '' installPhase = ''
@ -68,39 +66,8 @@
''; '';
installPhase = ''mv static $out''; installPhase = ''mv static $out'';
}; };
packages.e11sync = pkgs.stdenv.mkDerivation { packages.e11sync = pkgs.callPackage ./pkgs/e11sync.nix {
name = "e11sync"; inherit self geoip-archive;
propagatedBuildInputs = [runtimeDeps];
nativeBuildInputs = [pkgs.makeWrapper];
src = self;
dontUnpack = true;
buildPhase = ''
mkdir -p $out;
cp -r ${self}/app $out
makeWrapper ${pkgs.python3Packages.gunicorn}/bin/gunicorn $out/bin/e11sync-gunicorn \
--chdir $out/app \
--set-default E11SYNC_HTTP_PORT ${toString gunicornPort} \
--set E11SYNC_DEBUG "" \
--set E11SYNC_COMPRESS_OFFLINE 1 \
--set GEOIP_PATH "${geoip}" \
--add-flags --bind=127.0.0.1:\$E11SYNC_HTTP_PORT \
--add-flags e11sync.wsgi
makeWrapper $out/app/manage.py $out/bin/e11sync \
--set GEOIP_PATH "${geoip}"
'';
passthru.tests = {
simple =
pkgs.runCommand "e11sync-test" {
src = self;
buildInputs = runtimeDeps ++ buildDeps;
} ''
mkdir -p $out
cd ${self}/app
export GEOIP_PATH="${geoip}"
${pkgs.python3}/bin/python3 ./manage.py test
'';
};
}; };
checks.e11sync = packages.e11sync.passthru.tests.simple; checks.e11sync = packages.e11sync.passthru.tests.simple;
@ -119,7 +86,7 @@
devShells.default = pkgs.mkShellNoCC { devShells.default = pkgs.mkShellNoCC {
packages = [pkgs.python3Packages.django-debug-toolbar] ++ runtimeDeps ++ buildDeps; packages = [pkgs.python3Packages.django-debug-toolbar] ++ runtimeDeps ++ buildDeps;
GEOIP_PATH = "${geoip}"; GEOIP_PATH = "${geoip-archive}";
E11SYNC_DEBUG = "1"; E11SYNC_DEBUG = "1";
LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive"; LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive";
}; };

57
pkgs/e11sync.nix Normal file
View File

@ -0,0 +1,57 @@
{
self,
stdenv,
runCommand,
makeWrapper,
python3,
python3Packages,
libmaxminddb,
dart-sass,
gunicornPort ? 8001,
geoip-archive,
}:
stdenv.mkDerivation {
name = "e11sync";
propagatedBuildInputs = [
python3Packages.django_5
python3Packages.django-compressor
python3Packages.geoip2
libmaxminddb
];
nativeBuildInputs = [makeWrapper];
src = self;
dontUnpack = true;
buildPhase = ''
mkdir -p $out;
cp -r ${self}/app $out
makeWrapper ${python3Packages.gunicorn}/bin/gunicorn $out/bin/e11sync-gunicorn \
--chdir $out/app \
--set-default E11SYNC_HTTP_PORT ${toString gunicornPort} \
--set E11SYNC_DEBUG "" \
--set E11SYNC_COMPRESS_OFFLINE 1 \
--set GEOIP_PATH "${geoip-archive}" \
--add-flags --bind=127.0.0.1:\$E11SYNC_HTTP_PORT \
--add-flags e11sync.wsgi
makeWrapper $out/app/manage.py $out/bin/e11sync \
--set GEOIP_PATH "${geoip-archive}"
'';
passthru.tests = {
simple =
runCommand "e11sync-test" {
src = self;
buildInputs = [
python3Packages.django_5
python3Packages.django-compressor
python3Packages.geoip2
libmaxminddb
dart-sass
];
} ''
mkdir -p $out
cd ${self}/app
export GEOIP_PATH="${geoip-archive}"
${python3}/bin/python3 ./manage.py test
'';
};
}