Skip to content

Commit b0f0719

Browse files
committed
Support custom database connection url
1 parent 090b0cd commit b0f0719

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

flake.nix

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,22 @@
2121
nixosConfigurations.testing = nixpkgs.lib.nixosSystem {
2222
inherit system;
2323
modules = [
24-
self.nixosModules.sourcebot
24+
({
25+
pkgs,
26+
lib,
27+
...
28+
}: {
29+
imports = [
30+
self.nixosModules.sourcebot
31+
];
32+
system.stateVersion = "25.05";
33+
boot.isContainer = true; # stop nix flake check complaining about missing root fs
34+
documentation.nixos.enable = false; # skip generating nixos docs
35+
virtualisation.vmVariant = {
36+
boot.isContainer = lib.mkForce false; # let vm variant create a virtual disk
37+
virtualisation.graphics = false; # connect serial console to terminal
38+
};
39+
})
2540
];
2641
};
2742

nix/nixosModule.nix

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ in {
3838
};
3939
authEnabled = mkOption {
4040
type = types.bool;
41-
default = false;
41+
default = true;
4242
description = "Enables authentication in SourceBot";
4343
};
4444
telemetryDisabled = mkOption {
@@ -76,6 +76,11 @@ in {
7676
default = 16379;
7777
description = "TCP port for the SourceBot Redis server to listen on";
7878
};
79+
databaseUrl = mkOption {
80+
type = types.nullOr types.str;
81+
default = "postgresql://sourcebot@localhost:${toString config.services.postgresql.settings.port}/sourcebot";
82+
description = "PostgreSQL connection URL for SourceBot. If not set, a local PostgreSQL server will be configured and used.";
83+
};
7984
};
8085

8186
config = mkIf cfg.enable {
@@ -155,8 +160,8 @@ in {
155160
Group = "sourcebot";
156161
ExecStart = "${pkgs.prisma}/bin/prisma migrate deploy --schema ${cfg.package}/packages/db/prisma/schema.prisma";
157162
Environment = [
158-
"DATABASE_URL=postgresql://sourcebot@localhost:${toString config.services.postgresql.settings.port}/sourcebot"
159163
"PATH=${makeBinPath (with pkgs; [prisma openssl])}"
164+
"DATABASE_URL=${cfg.databaseUrl}"
160165
];
161166
Restart = "on-failure";
162167
RestartSec = "5s";
@@ -178,15 +183,15 @@ in {
178183
"DATA_CACHE_DIR=${cfg.dataCacheDir}"
179184
"PORT=${toString cfg.port}"
180185
"HOSTNAME=${cfg.hostname}"
181-
"DATABASE_URL=postgresql://sourcebot@localhost:${toString config.services.postgresql.settings.port}/sourcebot"
186+
"DATABASE_URL=${cfg.databaseUrl}"
182187
"REDIS_URL=redis://localhost:${toString cfg.redisPort}"
183188
"CONFIG_PATH=${cfg.configPath}"
184189
"SOURCEBOT_LOG_LEVEL=${cfg.logLevel}"
185190
"SOURCEBOT_TENANCY_MODE=single"
186-
"SOURCEBOT_AUTH_ENABLED=${boolToString cfg.authEnabled}"
191+
"AUTH_CREDENTIALS_LOGIN_ENABLED=${boolToString cfg.authEnabled}"
187192
"SOURCEBOT_TELEMETRY_DISABLED=${boolToString cfg.telemetryDisabled}"
188193
"SOURCEBOT_PUBLIC_KEY_PATH=${cfg.package}/public.pem"
189-
"AUTH_URL=${cfg.authUrl}"
194+
"AUTH_URL=http://${cfg.hostname}:${toString cfg.port}"
190195
]
191196
++ optional (cfg.envFile == null) [
192197
"AUTH_SECRET=00000000000000000000000000000000000000000000"
@@ -217,7 +222,7 @@ in {
217222
"CONFIG_PATH=${cfg.configPath}"
218223
"SOURCEBOT_LOG_LEVEL=${cfg.logLevel}"
219224
"SOURCEBOT_TENANCY_MODE=single"
220-
"SOURCEBOT_AUTH_ENABLED=${boolToString cfg.authEnabled}"
225+
"AUTH_CREDENTIALS_LOGIN_ENABLED=${boolToString cfg.authEnabled}"
221226
"SOURCEBOT_TELEMETRY_DISABLED=${boolToString cfg.telemetryDisabled}"
222227
"SOURCEBOT_PUBLIC_KEY_PATH=${cfg.package}/public.pem"
223228
"AUTH_URL=http://${cfg.hostname}:${toString cfg.port}"

0 commit comments

Comments
 (0)