git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/discourse: Assert deployed PostgreSQL version

Assert that the PostgreSQL version being deployed is the one used upstream. Allow the user to override this assertion, since it's not always possible or preferable to use the recommended one.

commitcb80b67993d6ba195c3329606aab5fb981d8323c authortalyz <kim.lindberger@gmail.com> dateThu 27 May 2021, 11:41 (5 years ago) parent2dec0de
2 files changed+24
nixos/modules/services/web-apps/discourse.nix+22 nixos/tests/discourse.nix+2
nixos/modules/services/web-apps/discourse.nix+22
@@ -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
nixos/tests/discourse.nix+2
@@ -51,6 +51,8 @@ import ./make-test-python.nix (
5151
5252 environment.systemPackages = [ pkgs.jq ];
5353
54+ services.postgresql.package = pkgs.postgresql_13;
55+
5456 services.discourse = {
5557 enable = true;
5658 inherit admin;