From 6499795df1910a6bfeb0f7bd798660e9c26e18a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Sun, 14 Jan 2024 19:54:32 +0200 Subject: [PATCH] e11sync: move to it's own package --- flake.nix | 45 +++++--------------------------------- pkgs/e11sync.nix | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 39 deletions(-) create mode 100644 pkgs/e11sync.nix diff --git a/flake.nix b/flake.nix index 039da0b..a05d49f 100644 --- a/flake.nix +++ b/flake.nix @@ -30,16 +30,14 @@ ... }: flake-utils.lib.eachDefaultSystem (system: let - gunicornPort = 8001; - pkgs = import nixpkgs {inherit system;}; appDeps = with pkgs.python3Packages; [django_5 django-compressor]; runtimeDeps = with pkgs; appDeps ++ [python3Packages.geoip2 libmaxminddb]; buildDeps = with pkgs; appDeps ++ [dart-sass]; - geoip = pkgs.stdenv.mkDerivation { - name = "geoip"; + geoip-archive = pkgs.stdenv.mkDerivation { + name = "geoip-archive"; srcs = [geoip2-asn geoip2-city geoip2-country]; dontUnpack = true; installPhase = '' @@ -68,39 +66,8 @@ ''; installPhase = ''mv static $out''; }; - packages.e11sync = pkgs.stdenv.mkDerivation { - name = "e11sync"; - 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 - ''; - }; + packages.e11sync = pkgs.callPackage ./pkgs/e11sync.nix { + inherit self geoip-archive; }; checks.e11sync = packages.e11sync.passthru.tests.simple; @@ -113,13 +80,13 @@ export E11SYNC_DATABASE_PATH=$PWD/db.sqlite3 exec ${packages.e11sync}/bin/e11sync-gunicorn ''; - in "${wrapper}"; + in "${wrapper}"; }; devShells.default = pkgs.mkShellNoCC { packages = [pkgs.python3Packages.django-debug-toolbar] ++ runtimeDeps ++ buildDeps; - GEOIP_PATH = "${geoip}"; + GEOIP_PATH = "${geoip-archive}"; E11SYNC_DEBUG = "1"; LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive"; }; diff --git a/pkgs/e11sync.nix b/pkgs/e11sync.nix new file mode 100644 index 0000000..bf5721d --- /dev/null +++ b/pkgs/e11sync.nix @@ -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 + ''; + }; +}