{ stdenv, lib, poetry2nix, python, fetchFromGitLab, fetchurl, unzip }: let version = "3.0.7"; src = fetchFromGitLab { owner = "glitchtip"; repo = "glitchtip-backend"; sha256 = "sha256-Dcdvv9DkU9znlamcSkGB/her+Ib6kV4mTkei6zoeZfE="; rev = "v${version}"; }; frontend = fetchurl { url = "https://gitlab.com/api/v4/projects/15449363/jobs/artifacts/v${version}/download?job=build-assets"; sha256 = "sha256-dv5/ilzcdmA8Ljee7u//my+yf5zPGevFNY8ig5YgWl0="; }; pythonApp = poetry2nix.mkPoetryApplication rec { inherit python; projectDir = src; patches = [ ./glitchtip-fix-poetry-name.patch ./glitchtip-fix-versions.patch ]; # a bunch of python packages seem to misdeclare their dependencies # a few are also just broken when building with Nix, so use these # from nixpkgs instead. Finally, some are inherited from nixpkgs # just to prevent duplicate dependencies (where nixpkgs & glitchtip's # lock file differ in package versions) overrides = poetry2nix.defaultPoetryOverrides.extend (self: super: { anonymizeip = super.anonymizeip.overridePythonAttrs (old: { propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ super.setuptools ]; }); uwsgi-chunked = super.uwsgi-chunked.overridePythonAttrs (old: { propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ super.setuptools ]; }); django-bitfield = super.django-bitfield.overridePythonAttrs (old: { propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ super.setuptools ]; }); roundrobin = super.roundrobin.overridePythonAttrs (old: { propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ super.setuptools ]; }); markuppy = super.markuppy.overridePythonAttrs (old: { propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ super.setuptools ]; }); uwsgi = super.uwsgi.overridePythonAttrs (old: { propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ super.setuptools ]; }); inherit (python.pkgs) django-stubs-ext django-stubs django async-timeout mypy-extensions tomli asgiref sqlparse typing-extensions pytz mypy; }); # magically makes the cargo errors go away preferWheels = true; }; staticDir = stdenv.mkDerivation { pname = "glitchtip-backend-static"; inherit version; inherit src; buildInputs = [ unzip ]; propagatedBuildInputs = [ pythonApp.dependencyEnv ]; buildPhase = '' unzip ${frontend} -d unpacked mv unpacked/dist/glitchtip-frontend dist rm -rf unpacked ${pythonApp.dependencyEnv}/bin/python ${src}/manage.py collectstatic ''; installPhase = '' mkdir -p $out cp -r * $out rm $out/manage.py install -Dm755 manage.py $out/manage.py ''; }; # this is mildly cursed. It returns the static dir as a package, # but keeps the Nix meta-info of pythonApp in the attr set so we can # also feed this to pythonPackages and the like to get a python env. in pythonApp // staticDir