@@ -5,11 +5,16 @@ let
55
66 cfg = config.services.discourse;
77
8+ # Keep in sync with https://github.com/discourse/discourse_docker/blob/master/image/base/Dockerfile#L5
9+ upstreamPostgresqlVersion = lib.getVersion pkgs.postgresql_13;
10+
811 postgresqlPackage = if config.services.postgresql.enable then
912 config.services.postgresql.package
1013 else
1114 pkgs.postgresql;
1215
16+ postgresqlVersion = lib.getVersion postgresqlPackage;
17+
1318 # We only want to create a database if we're actually going to connect to it.
1419 databaseActuallyCreateLocally = cfg.database.createLocally && cfg.database.host == null;
1520
@@ -263,6 +268,17 @@ in
263268 Discourse database user.
264269 '';
265270 };
271+
272+ ignorePostgresqlVersion = lib.mkOption {
273+ type = lib.types.bool;
274+ default = false;
275+ description = ''
276+ Whether to allow other versions of PostgreSQL than the
277+ recommended one. Only effective when
278+ <option>services.discourse.database.createLocally</option>
279+ is enabled.
280+ '';
281+ };
266282 };
267283
268284 redis = {
@@ -505,6 +521,12 @@ in
505521 assertion = cfg.hostname != "";
506522 message = "Could not automatically determine hostname, set service.discourse.hostname manually.";
507523 }
524+ {
525+ assertion = cfg.database.ignorePostgresqlVersion || (databaseActuallyCreateLocally -> upstreamPostgresqlVersion == postgresqlVersion);
526+ message = "The PostgreSQL version recommended for use with Discourse is ${upstreamPostgresqlVersion}, you're using ${postgresqlVersion}. "
527+ + "Either update your PostgreSQL package to the correct version or set services.discourse.database.ignorePostgresqlVersion. "
528+ + "See https://nixos.org/manual/nixos/stable/index.html#module-postgresql for details on how to upgrade PostgreSQL.";
529+ }
508530 ];
509531
510532