{ nixConfig = { trusted-substituters = "https://cache.nixos.org/"; trusted-public-keys = "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="; extra-experimental-features = "nix-command flakes"; }; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; flake-utils.url = "github:numtide/flake-utils"; geoip2-asn = { url = "https://dl.jakstys.lt/_/2024.01.10/GeoLite2-ASN.mmdb"; flake = false; }; geoip2-city = { url = "https://dl.jakstys.lt/_/2024.01.10/GeoLite2-City.mmdb"; flake = false; }; geoip2-country = { url = "https://dl.jakstys.lt/_/2024.01.10/GeoLite2-Country.mmdb"; flake = false; }; }; outputs = { self, nixpkgs, flake-utils, geoip2-asn, geoip2-city, geoip2-country, ... }: 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"; srcs = [geoip2-asn geoip2-city geoip2-country]; dontUnpack = true; installPhase = '' mkdir -p $out cp ${geoip2-asn} $out/GeoLite2-ASN.mmdb cp ${geoip2-city} $out/GeoLite2-City.mmdb cp ${geoip2-country} $out/GeoLite2-Country.mmdb ''; }; in rec { packages.e11sync-static = pkgs.stdenv.mkDerivation { name = "e11sync-static"; src = self; nativeBuildInputs = buildDeps; buildPhase = with pkgs; '' mkdir -p static export E11SYNC_STATIC_ROOT=static export E11SYNC_DEBUG= export E11SYNC_COMPRESS_OFFLINE=1 ${python3}/bin/python3 ${self}/app/manage.py collectstatic ${python3}/bin/python3 ${self}/app/manage.py compress ${findutils}/bin/find static/CACHE -name '*.css' | \ ${findutils}/bin/xargs -P''$(${coreutils}/bin/nproc) -I{} sh -c \ "${zopfli}/bin/zopfli {} && ${brotli}/bin/brotli {}" ''; 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 ''; }; }; checks.e11sync = packages.e11sync.passthru.tests.simple; apps.e11sync-gunicorn = { type = "app"; name = "e11sync-gunicorn"; program = let wrapper = pkgs.writeShellScript "wrapper" '' export E11SYNC_DATABASE_PATH=$PWD/db.sqlite3 exec ${packages.e11sync}/bin/e11sync-gunicorn ''; in "${wrapper}"; }; devShells.default = pkgs.mkShellNoCC { packages = [pkgs.python3Packages.django-debug-toolbar] ++ runtimeDeps ++ buildDeps; GEOIP_PATH = "${geoip}"; E11SYNC_DEBUG = "1"; LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive"; }; formatter = pkgs.alejandra; }); }