2023-12-14 18:16:04 +02:00
|
|
|
{
|
|
|
|
nixConfig = {
|
|
|
|
trusted-substituters = "https://cache.nixos.org/";
|
|
|
|
trusted-public-keys = "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=";
|
|
|
|
extra-experimental-features = "nix-command flakes";
|
|
|
|
};
|
|
|
|
inputs = {
|
2024-01-07 23:07:09 +02:00
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
|
2023-12-14 18:16:04 +02:00
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
2024-01-12 01:15:11 +02:00
|
|
|
geoip2-asn = {
|
2024-01-12 07:38:22 +02:00
|
|
|
url = "https://dl.jakstys.lt/_/2024.01.10/GeoLite2-ASN.mmdb";
|
2024-01-12 01:15:11 +02:00
|
|
|
flake = false;
|
|
|
|
};
|
|
|
|
geoip2-city = {
|
2024-01-12 07:38:22 +02:00
|
|
|
url = "https://dl.jakstys.lt/_/2024.01.10/GeoLite2-City.mmdb";
|
2024-01-12 01:15:11 +02:00
|
|
|
flake = false;
|
|
|
|
};
|
|
|
|
geoip2-country = {
|
2024-01-12 07:38:22 +02:00
|
|
|
url = "https://dl.jakstys.lt/_/2024.01.10/GeoLite2-Country.mmdb";
|
2024-01-12 01:15:11 +02:00
|
|
|
flake = false;
|
|
|
|
};
|
2023-12-14 18:16:04 +02:00
|
|
|
};
|
|
|
|
outputs = {
|
|
|
|
self,
|
|
|
|
nixpkgs,
|
|
|
|
flake-utils,
|
2024-01-12 01:15:11 +02:00
|
|
|
geoip2-asn,
|
|
|
|
geoip2-city,
|
|
|
|
geoip2-country,
|
2023-12-14 18:16:04 +02:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
flake-utils.lib.eachDefaultSystem (system: let
|
|
|
|
pkgs = import nixpkgs {inherit system;};
|
2024-01-13 17:40:12 +02:00
|
|
|
gunicornPort = 8001;
|
2024-01-13 17:00:02 +02:00
|
|
|
|
|
|
|
appDeps = with pkgs; [
|
2023-12-25 18:08:07 +02:00
|
|
|
python3Packages.django_5
|
2023-12-15 11:51:39 +02:00
|
|
|
python3Packages.django-compressor
|
2023-12-14 18:24:10 +02:00
|
|
|
];
|
2024-01-13 17:00:02 +02:00
|
|
|
runtimeDeps = with pkgs;
|
|
|
|
[
|
|
|
|
python3Packages.geoip2
|
|
|
|
libmaxminddb
|
|
|
|
]
|
|
|
|
++ appDeps;
|
|
|
|
buildDeps = [pkgs.dart-sass] ++ appDeps;
|
|
|
|
|
2024-01-12 01:15:11 +02:00
|
|
|
geoip = pkgs.stdenv.mkDerivation {
|
2024-01-12 01:31:38 +02:00
|
|
|
name = "geoip";
|
2024-01-12 01:15:11 +02:00
|
|
|
srcs = [geoip2-asn geoip2-city geoip2-country];
|
|
|
|
dontUnpack = true;
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out
|
2024-01-12 01:31:38 +02:00
|
|
|
cp ${geoip2-asn} $out/GeoLite2-ASN.mmdb
|
|
|
|
cp ${geoip2-city} $out/GeoLite2-City.mmdb
|
|
|
|
cp ${geoip2-country} $out/GeoLite2-Country.mmdb
|
2024-01-12 01:15:11 +02:00
|
|
|
'';
|
|
|
|
};
|
2024-01-13 17:45:12 +02:00
|
|
|
in rec {
|
2024-01-13 09:59:21 +02:00
|
|
|
packages.e11sync-static = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "e11sync-static";
|
|
|
|
src = self;
|
2024-01-13 17:00:02 +02:00
|
|
|
nativeBuildInputs = buildDeps;
|
2024-01-13 09:59:21 +02:00
|
|
|
buildPhase = ''
|
2024-01-13 17:00:02 +02:00
|
|
|
mkdir -p $out/static
|
|
|
|
export E11SYNC_STATIC_ROOT=$out/static
|
|
|
|
export E11SYNC_DEBUG=
|
|
|
|
export E11SYNC_COMPRESS_OFFLINE=1
|
|
|
|
${pkgs.python3}/bin/python3 ${self}/app/manage.py collectstatic
|
|
|
|
${pkgs.python3}/bin/python3 ${self}/app/manage.py compress
|
2024-01-13 15:12:05 +02:00
|
|
|
|
2024-01-13 17:00:02 +02:00
|
|
|
${pkgs.findutils}/bin/find $out/static/CACHE -name '*.css' | \
|
|
|
|
${pkgs.findutils}/bin/xargs -P8 -I{} sh -c \
|
|
|
|
"${pkgs.zopfli}/bin/zopfli {} && ${pkgs.brotli}/bin/brotli {}"
|
2024-01-13 09:59:21 +02:00
|
|
|
'';
|
|
|
|
};
|
2024-01-13 17:40:12 +02:00
|
|
|
packages.e11sync-gunicorn = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "e11sync-gunicorn";
|
2024-01-13 17:00:02 +02:00
|
|
|
propagatedBuildInputs = [runtimeDeps];
|
|
|
|
nativeBuildInputs = [pkgs.makeWrapper];
|
|
|
|
src = self;
|
|
|
|
dontUnpack = true;
|
|
|
|
buildPhase = ''
|
2024-01-13 17:45:12 +02:00
|
|
|
mkdir -p $out;
|
|
|
|
cp -r ${self}/app $out
|
|
|
|
makeWrapper ${pkgs.python3Packages.gunicorn}/bin/gunicorn $out/bin/entrypoint \
|
|
|
|
--chdir $out/app \
|
|
|
|
--set E11SYNC_DEBUG "" \
|
|
|
|
--set E11SYNC_COMPRESS_OFFLINE 1 \
|
|
|
|
--set GEOIP_PATH "${geoip}" \
|
|
|
|
--add-flags e11sync.wsgi \
|
|
|
|
--add-flags --bind=127.0.0.1:${toString gunicornPort}
|
|
|
|
'';
|
2024-01-13 18:07:24 +02:00
|
|
|
passthru.tests = {
|
|
|
|
simple = pkgs.runCommand {} "e11sync-test" ''
|
|
|
|
exit 1;
|
|
|
|
'';
|
|
|
|
};
|
2024-01-13 17:45:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
apps.e11sync-gunicorn = {
|
|
|
|
type = "app";
|
|
|
|
name = "e11sync-gunicorn";
|
|
|
|
program = "${packages.e11sync-gunicorn}/bin/entrypoint";
|
2024-01-13 17:00:02 +02:00
|
|
|
};
|
|
|
|
|
2024-01-12 12:53:02 +02:00
|
|
|
devShells.default = pkgs.mkShellNoCC {
|
2023-12-14 18:16:04 +02:00
|
|
|
LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive";
|
2024-01-12 01:31:38 +02:00
|
|
|
GEOIP_PATH = "${geoip}";
|
2024-01-13 09:59:21 +02:00
|
|
|
E11SYNC_DEBUG = "1";
|
2024-01-13 18:07:24 +02:00
|
|
|
packages = [pkgs.python3Packages.django-debug-toolbar] ++ runtimeDeps ++ buildDeps;
|
2023-12-14 18:16:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
formatter = pkgs.alejandra;
|
|
|
|
});
|
|
|
|
}
|