summaryrefslogtreecommitdiff
path: root/modules/glitchtip.nix
blob: f55f9e947d9c2aadb986d9a02fdb745d7bebdfa1 (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
{ config, lib, pkgs, ... }:

with lib;

let cfg = config.services.glitchtip;
in {
  options.services.glitchtip = with types; {
    enable = mkOption {
      type = types.bool;
      default = false;
      description = "Enables glitchtip. This module is bring-your-own redis & postgres (look at redisUrl & databaseUrl); both are required for glitchtip to run without errors";
    };

    databaseUrl = mkOption {
      type = str;
      default = "postgres://glitchtip@localhost:5432/glitchtip";
      description = "how to connect to postgres. An empty database (e.g. created by services.postgresql.ensureDatabases) is sufficient; migrations will be run automatically on startup.";
    };

    redisUrl = mkOption {
      type = str;
      default = "redis://localhost";
      description = "how to connect to redis";
    };

    domain = mkOption {
      type = str;
      default = "http://localhost:${toString cfg.port}";
      description = "your glitchtip's public-facing domain. Must include the schema (http/https).";
    };

    package = mkOption {
      type = package;
      default = pkgs.glitchtip;
    };

    port = mkOption {
      type = port;
      default = 8000;
      description = "port for glitchtip's uwsgi server";
    };
  };

  config = mkIf cfg.enable {
    services.uwsgi = {
      enable = true;
      plugins = [ "python3" ];
      instance = {
        type = "normal";
        pythonPackages = _: [ cfg.package ];
        module = "glitchtip.wsgi:application";
        chdir = cfg.package;
        threads = 4;
        http = ":${toString cfg.port}";
        env = [
          "DATABASE_URL=${cfg.databaseUrl}"
          "GLITCHTIP_DOMAIN=${cfg.domain}"
          "REDIS_URL=${cfg.redisUrl}"
        ];
        hook-pre-app = ''
          exec:./manage.py migrate
        '';
      };
    };

    systemd.services."glitchtip-celery" = {
      enable = true;
      wantedBy = [ "uwsgi.service" ];
      serviceConfig.Type = "simple";
      path = [ cfg.package.dependencyEnv ];
      script = ''
        cd ${cfg.package}
        bin/run-celery-with-beat.sh
      '';
      environment = {
        DATABASE_URL = cfg.databaseUrl;
        REDIS_URL = cfg.redisUrl;
      };
    };
  };
}