From cb80b67993d6ba195c3329606aab5fb981d8323c Mon Sep 17 00:00:00 2001 From: talyz Date: Thu, 27 May 2021 11:41:35 +0200 Subject: [PATCH] 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. --- nixos/modules/services/web-apps/discourse.nix | 22 +++++++++++++++++++ nixos/tests/discourse.nix | 2 ++ 2 files changed, 24 insertions(+) diff --git a/nixos/modules/services/web-apps/discourse.nix b/nixos/modules/services/web-apps/discourse.nix index ba5989800ea..49958fc6190 100644 --- a/nixos/modules/services/web-apps/discourse.nix +++ b/nixos/modules/services/web-apps/discourse.nix @@ -5,11 +5,16 @@ let cfg = config.services.discourse; + # Keep in sync with https://github.com/discourse/discourse_docker/blob/master/image/base/Dockerfile#L5 + upstreamPostgresqlVersion = lib.getVersion pkgs.postgresql_13; + postgresqlPackage = if config.services.postgresql.enable then config.services.postgresql.package else pkgs.postgresql; + postgresqlVersion = lib.getVersion postgresqlPackage; + # We only want to create a database if we're actually going to connect to it. databaseActuallyCreateLocally = cfg.database.createLocally && cfg.database.host == null; @@ -263,6 +268,17 @@ in Discourse database user. ''; }; + + ignorePostgresqlVersion = lib.mkOption { + type = lib.types.bool; + default = false; + description = '' + Whether to allow other versions of PostgreSQL than the + recommended one. Only effective when + + is enabled. + ''; + }; }; redis = { @@ -505,6 +521,12 @@ in assertion = cfg.hostname != ""; message = "Could not automatically determine hostname, set service.discourse.hostname manually."; } + { + assertion = cfg.database.ignorePostgresqlVersion || (databaseActuallyCreateLocally -> upstreamPostgresqlVersion == postgresqlVersion); + message = "The PostgreSQL version recommended for use with Discourse is ${upstreamPostgresqlVersion}, you're using ${postgresqlVersion}. " + + "Either update your PostgreSQL package to the correct version or set services.discourse.database.ignorePostgresqlVersion. " + + "See https://nixos.org/manual/nixos/stable/index.html#module-postgresql for details on how to upgrade PostgreSQL."; + } ]; diff --git a/nixos/tests/discourse.nix b/nixos/tests/discourse.nix index 3c965550fe0..2ed6fb957c2 100644 --- a/nixos/tests/discourse.nix +++ b/nixos/tests/discourse.nix @@ -51,6 +51,8 @@ import ./make-test-python.nix ( environment.systemPackages = [ pkgs.jq ]; + services.postgresql.package = pkgs.postgresql_13; + services.discourse = { enable = true; inherit admin;