115 lines
3.5 KiB
Nix
115 lines
3.5 KiB
Nix
{
|
|
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
|
|
pkgs = import nixpkgs {inherit system;};
|
|
uwsgiPort = 8001;
|
|
|
|
uwsgi = pkgs.uwsgi.override {
|
|
plugins = ["python3"];
|
|
python3 = pkgs.python3;
|
|
};
|
|
|
|
appDeps = with pkgs; [
|
|
python3Packages.django_5
|
|
python3Packages.django-compressor
|
|
];
|
|
runtimeDeps = with pkgs;
|
|
[
|
|
python3Packages.geoip2
|
|
libmaxminddb
|
|
]
|
|
++ appDeps;
|
|
buildDeps = [pkgs.dart-sass] ++ appDeps;
|
|
debugDeps = [pkgs.python3Packages.django-debug-toolbar] ++ runtimeDeps;
|
|
|
|
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 {
|
|
packages.e11sync-static = pkgs.stdenv.mkDerivation {
|
|
name = "e11sync-static";
|
|
src = self;
|
|
nativeBuildInputs = buildDeps;
|
|
buildPhase = ''
|
|
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
|
|
|
|
${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 {}"
|
|
'';
|
|
};
|
|
packages.e11sync-uwsgi = pkgs.stdenv.mkDerivation {
|
|
name = "e11sync-uwsgi";
|
|
propagatedBuildInputs = [runtimeDeps];
|
|
nativeBuildInputs = [pkgs.makeWrapper];
|
|
src = self;
|
|
dontUnpack = true;
|
|
buildPhase = ''
|
|
mkdir -p $out;
|
|
cp -r ${self}/app $out
|
|
makeWrapper ${uwsgi}/bin/uwsgi $out/bin/entrypoint-uwsgi \
|
|
--add-flags '\
|
|
--chdir='"$out"'/app \
|
|
--module=e11sync.wsgi:application \
|
|
--master \
|
|
--http-socket=127.0.0.1:${toString uwsgiPort} \
|
|
--processes=5 \
|
|
--harakiri=20 \
|
|
--max-requests=10000 \
|
|
--vacuum'
|
|
'';
|
|
};
|
|
|
|
devShells.default = pkgs.mkShellNoCC {
|
|
LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive";
|
|
GEOIP_PATH = "${geoip}";
|
|
E11SYNC_DEBUG = "1";
|
|
packages = debugDeps;
|
|
};
|
|
|
|
formatter = pkgs.alejandra;
|
|
});
|
|
}
|