@@ -18,7 +18,12 @@ let
1818 else toString value;
1919
2020 # The main PostgreSQL configuration file.
21− configFile = pkgs.writeText "postgresql.conf" (concatStringsSep "\n" (mapAttrsToList (n: v: "${n} = ${toStr v}") cfg.settings));
21+ configFile = pkgs.writeTextDir "postgresql.conf" (concatStringsSep "\n" (mapAttrsToList (n: v: "${n} = ${toStr v}") cfg.settings));
22+
23+ configFileCheck = pkgs.runCommand "postgresql-configfile-check" {} ''
24+ ${cfg.package}/bin/postgres -D${configFile} -C config_file >/dev/null
25+ touch $out
26+ '';
2227
2328 groupAccessAvailable = versionAtLeast postgresql.version "11.0";
2429
@@ -53,6 +58,12 @@ in
5358 '';
5459 };
5560
61+ checkConfig = mkOption {
62+ type = types.bool;
63+ default = true;
64+ description = "Check the syntax of the configuration file at compile time";
65+ };
66+
5667 dataDir = mkOption {
5768 type = types.path;
5869 defaultText = "/var/lib/postgresql/\${config.services.postgresql.package.psqlSchema}";
@@ -314,6 +325,8 @@ in
314325 "/share/postgresql"
315326 ];
316327
328+ system.extraDependencies = lib.optional (cfg.checkConfig && pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) configFileCheck;
329+
317330 systemd.services.postgresql =
318331 { description = "PostgreSQL Server";
319332
@@ -337,7 +350,7 @@ in
337350 touch "${cfg.dataDir}/.first_startup"
338351 fi
339352
340− ln -sfn "${configFile}" "${cfg.dataDir}/postgresql.conf"
353+ ln -sfn "${configFile}/postgresql.conf" "${cfg.dataDir}/postgresql.conf"
341354 ${optionalString (cfg.recoveryConfig != null) ''
342355 ln -sfn "${pkgs.writeText "recovery.conf" cfg.recoveryConfig}" \
343356 "${cfg.dataDir}/recovery.conf"