WIP! A BB-style forum, on the ATmosphere! We're still working... we'll be back soon when we have something to show off!
node typescript hono htmx atproto
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(nix): add database.type option to NixOS module (postgresql | sqlite)

Malpercio e5bb6c8b b496a176

+25 -5
+25 -5
nix/module.nix
··· 62 62 }; 63 63 64 64 database = { 65 + type = lib.mkOption { 66 + type = lib.types.enum [ "postgresql" "sqlite" ]; 67 + default = "postgresql"; 68 + description = "Database backend. Use 'sqlite' for embedded single-file storage without a separate PostgreSQL service."; 69 + }; 70 + 71 + path = lib.mkOption { 72 + type = lib.types.path; 73 + default = "/var/lib/atbb/atbb.db"; 74 + description = "Path to the SQLite database file. Only used when database.type = \"sqlite\"."; 75 + }; 76 + 65 77 enable = lib.mkOption { 66 78 type = lib.types.bool; 67 - default = true; 68 - description = "Whether to configure a local PostgreSQL 17 instance."; 79 + default = cfg.database.type == "postgresql"; 80 + description = "Enable local PostgreSQL 17 service. Ignored when database.type = \"sqlite\"."; 69 81 }; 70 82 71 83 name = lib.mkOption { ··· 155 167 users.groups.${cfg.group} = { }; 156 168 157 169 # ── PostgreSQL ─────────────────────────────────────────────── 158 - services.postgresql = lib.mkIf cfg.database.enable { 170 + services.postgresql = lib.mkIf (cfg.database.type == "postgresql" && cfg.database.enable) { 159 171 enable = true; 160 172 package = pkgs.postgresql_17; 161 173 ensureDatabases = [ cfg.database.name ]; ··· 189 201 User = cfg.user; 190 202 Group = cfg.group; 191 203 WorkingDirectory = "${cfg.package}/apps/appview"; 192 - ExecStart = "${cfg.package}/apps/appview/node_modules/.bin/drizzle-kit migrate"; 204 + ExecStart = if cfg.database.type == "sqlite" 205 + then "${cfg.package}/apps/appview/node_modules/.bin/drizzle-kit migrate --config=drizzle.sqlite.config.ts" 206 + else "${cfg.package}/apps/appview/node_modules/.bin/drizzle-kit migrate --config=drizzle.postgres.config.ts"; 193 207 EnvironmentFile = cfg.environmentFile; 194 208 RemainAfterExit = true; 195 209 ··· 223 237 PDS_URL = cfg.pdsUrl; 224 238 OAUTH_PUBLIC_URL = cfg.oauthPublicUrl; 225 239 SEED_DEFAULT_ROLES = lib.boolToString cfg.seedDefaultRoles; 226 - } // lib.optionalAttrs cfg.database.enable { 240 + } // lib.optionalAttrs (cfg.database.type == "sqlite") { 241 + # SQLite: set DATABASE_URL from module config (not env file) 242 + DATABASE_URL = "file:${cfg.database.path}"; 243 + } // lib.optionalAttrs (cfg.database.type == "postgresql" && cfg.database.enable) { 227 244 # Explicit socket directory so postgres.js uses Unix peer auth 228 245 # regardless of how it parses the DATABASE_URL host parameter. 229 246 PGHOST = "/run/postgresql"; ··· 238 255 EnvironmentFile = cfg.environmentFile; 239 256 Restart = "on-failure"; 240 257 RestartSec = 5; 258 + 259 + # SQLite: create /var/lib/atbb/ and grant write access to the service user 260 + StateDirectory = lib.mkIf (cfg.database.type == "sqlite") "atbb"; 241 261 242 262 # Hardening 243 263 NoNewPrivileges = true;