Skip to content

Commit 4fce038

Browse files
nixos/glitchtip: add nginx.createLocally option
1 parent e5026c1 commit 4fce038

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

nixos/modules/services/web-apps/glitchtip.nix

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ in
5353

5454
settings = lib.mkOption {
5555
description = ''
56-
Configuration of GlitchTip. See <https://glitchtip.com/documentation/install#configuration> for more information.
56+
Configuration of GlitchTip. See <https://glitchtip.com/documentation/install#configuration> for more information and required settings.
5757
'';
5858
default = { };
5959
defaultText = lib.literalExpression ''
@@ -62,6 +62,7 @@ in
6262
DEBUG_TOOLBAR = 0;
6363
DATABASE_URL = lib.mkIf config.services.glitchtip.database.createLocally "postgresql://@/glitchtip";
6464
ENABLE_OBSERVABILITY_API = false;
65+
GLITCHTIP_DOMAIN = lib.mkIf config.services.glitchtip.nginx.createLocally "https://''${config.services.glitchtip.nginx.domain}";
6566
GLITCHTIP_ENABLE_MCP = false;
6667
GLITCHTIP_VERSION = config.services.glitchtip.package.version;
6768
GRANIAN_HOST = "127.0.0.1";
@@ -73,6 +74,7 @@ in
7374
}
7475
'';
7576
example = {
77+
GLITCHTIP_DOMAIN = "https://glitchtip.example.com";
7678
DATABASE_URL = "postgres://postgres:postgres@postgres/postgres";
7779
};
7880

@@ -86,6 +88,13 @@ in
8688
]);
8789

8890
options = {
91+
GLITCHTIP_DOMAIN = lib.mkOption {
92+
type = lib.types.nullOr lib.types.str;
93+
description = "The URL under which GlitchTip is externally reachable.";
94+
example = "https://glitchtip.example.com";
95+
default = null;
96+
};
97+
8998
GLITCHTIP_ENABLE_MCP = lib.mkOption {
9099
type = lib.types.bool;
91100
description = "Whether to enable the MCP api.";
@@ -137,17 +146,31 @@ in
137146
database.createLocally = lib.mkOption {
138147
type = lib.types.bool;
139148
default = true;
140-
description = ''
141-
Whether to enable and configure a local PostgreSQL database server.
142-
'';
149+
description = "Whether to enable and configure a local PostgreSQL database server.";
150+
};
151+
152+
nginx = {
153+
createLocally = lib.mkOption {
154+
type = lib.types.bool;
155+
default = false;
156+
description = "Whether to enable and configure a local Nginx server.";
157+
};
158+
159+
domain = lib.mkOption {
160+
type = lib.types.str;
161+
example = "glitchtip.example.com";
162+
description = ''
163+
Domain under which GlitchTip will be reachable.
164+
In contrast to `settings.GLITCHTIP_DOMAIN` this option has no protocol.
165+
It will also set `settings.GLITCHTIP_DOMAIN` with the `https://` protocol.
166+
'';
167+
};
143168
};
144169

145170
redis.createLocally = lib.mkOption {
146171
type = lib.types.bool;
147172
default = true;
148-
description = ''
149-
Whether to enable and configure a local Redis instance.
150-
'';
173+
description = "Whether to enable and configure a local Redis instance.";
151174
};
152175
};
153176
};
@@ -185,6 +208,9 @@ in
185208
// lib.optionalAttrs cfg.database.createLocally {
186209
DATABASE_URL = "postgresql://@/glitchtip";
187210
}
211+
// lib.optionalAttrs cfg.nginx.createLocally {
212+
GLITCHTIP_DOMAIN = "https://${cfg.nginx.domain}";
213+
}
188214
// lib.optionalAttrs cfg.redis.createLocally {
189215
REDIS_URL = "unix://${config.services.redis.servers.glitchtip.unixSocket}";
190216
};
@@ -290,6 +316,22 @@ in
290316
};
291317
};
292318

319+
services.nginx = lib.mkIf cfg.nginx.createLocally {
320+
enable = true;
321+
virtualHosts.${cfg.nginx.domain} = {
322+
forceSSL = lib.mkDefault true;
323+
locations = {
324+
"/".proxyPass = "http://${cfg.settings.GRANIAN_HOST}:${toString cfg.settings.GRANIAN_PORT}";
325+
"/static/" = {
326+
root = pkg;
327+
extraConfig = ''
328+
rewrite ^/(.*)$ /lib/glitchtip/$1 break;
329+
'';
330+
};
331+
};
332+
};
333+
};
334+
293335
services.postgresql = lib.mkIf cfg.database.createLocally {
294336
enable = true;
295337
ensureDatabases = [ "glitchtip" ];

pkgs/by-name/gl/glitchtip/package.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ stdenv.mkDerivation (finalAttrs: {
8888
hash = "sha256-cv83nqoJob8rvBOFDUIr8kVSZQesG/ml+6n7yuZqP90=";
8989
};
9090

91+
postPatch = ''
92+
echo 'import os
93+
ALLAUTH_TRUSTED_CLIENT_IP_HEADER = os.getenv(
94+
"ALLAUTH_TRUSTED_CLIENT_IP_HEADER",
95+
None
96+
)' >> glitchtip/settings.py
97+
'';
98+
9199
propagatedBuildInputs = pythonPackages;
92100

93101
nativeBuildInputs = [

0 commit comments

Comments
 (0)