summaryrefslogtreecommitdiff
path: root/pkgs/glitchtip.nix
blob: 380eb48e300f3925d2971a970e59f20ec8526a36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{ 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 = [
      ./0001-fix-poetry-name-issue.patch
      ./0002-fix-django-version-bound.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