From 7c4ce3a545fb74ab1eb35c02de9ace3c3dbae2ef Mon Sep 17 00:00:00 2001 From: stuebinm Date: Wed, 22 Mar 2023 18:34:32 +0100 Subject: a glitchtip module, because why not in case i ever think i need such a thing, i guess --- modules/glitchtip.nix | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 modules/glitchtip.nix (limited to 'modules') diff --git a/modules/glitchtip.nix b/modules/glitchtip.nix new file mode 100644 index 0000000..f55f9e9 --- /dev/null +++ b/modules/glitchtip.nix @@ -0,0 +1,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; + }; + }; + }; +} -- cgit v1.2.3