summary refs log tree commit diff
path: root/nixos/modules/services/databases
diff options
context:
space:
mode:
authorGuillaume Girol <symphorien@users.noreply.github.com>2021-04-02 16:27:03 +0000
committerGitHub <noreply@github.com>2021-04-02 16:27:03 +0000
commitfe0e0afbc0fbf1d1f71577a38a11c1eb7f63745e (patch)
treef2e6b943f6d67960a1515dc6a518c6ac20d739e6 /nixos/modules/services/databases
parent5e237d6827825cf388d4fe7fbc5d13ed5bc3132d (diff)
parent1b7ca69ecc47c807df21c1291c98fec0d4e294db (diff)
downloadnixpkgs-fe0e0afbc0fbf1d1f71577a38a11c1eb7f63745e.tar
nixpkgs-fe0e0afbc0fbf1d1f71577a38a11c1eb7f63745e.tar.gz
nixpkgs-fe0e0afbc0fbf1d1f71577a38a11c1eb7f63745e.tar.bz2
nixpkgs-fe0e0afbc0fbf1d1f71577a38a11c1eb7f63745e.tar.lz
nixpkgs-fe0e0afbc0fbf1d1f71577a38a11c1eb7f63745e.tar.xz
nixpkgs-fe0e0afbc0fbf1d1f71577a38a11c1eb7f63745e.tar.zst
nixpkgs-fe0e0afbc0fbf1d1f71577a38a11c1eb7f63745e.zip
Merge pull request #92929 from symphorien/postgresql-check-config-file
nixos/postgresql: check config file syntax at build time
Diffstat (limited to 'nixos/modules/services/databases')
-rw-r--r--nixos/modules/services/databases/postgresql.nix17
1 files changed, 15 insertions, 2 deletions
diff --git a/nixos/modules/services/databases/postgresql.nix b/nixos/modules/services/databases/postgresql.nix
index f582b059277..900185fbbdf 100644
--- a/nixos/modules/services/databases/postgresql.nix
+++ b/nixos/modules/services/databases/postgresql.nix
@@ -18,7 +18,12 @@ let
     else toString value;
 
   # The main PostgreSQL configuration file.
-  configFile = pkgs.writeText "postgresql.conf" (concatStringsSep "\n" (mapAttrsToList (n: v: "${n} = ${toStr v}") cfg.settings));
+  configFile = pkgs.writeTextDir "postgresql.conf" (concatStringsSep "\n" (mapAttrsToList (n: v: "${n} = ${toStr v}") cfg.settings));
+
+  configFileCheck = pkgs.runCommand "postgresql-configfile-check" {} ''
+    ${cfg.package}/bin/postgres -D${configFile} -C config_file >/dev/null
+    touch $out
+  '';
 
   groupAccessAvailable = versionAtLeast postgresql.version "11.0";
 
@@ -53,6 +58,12 @@ in
         '';
       };
 
+      checkConfig = mkOption {
+        type = types.bool;
+        default = true;
+        description = "Check the syntax of the configuration file at compile time";
+      };
+
       dataDir = mkOption {
         type = types.path;
         defaultText = "/var/lib/postgresql/\${config.services.postgresql.package.psqlSchema}";
@@ -314,6 +325,8 @@ in
      "/share/postgresql"
     ];
 
+    system.extraDependencies = lib.optional (cfg.checkConfig && pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) configFileCheck;
+
     systemd.services.postgresql =
       { description = "PostgreSQL Server";
 
@@ -337,7 +350,7 @@ in
               touch "${cfg.dataDir}/.first_startup"
             fi
 
-            ln -sfn "${configFile}" "${cfg.dataDir}/postgresql.conf"
+            ln -sfn "${configFile}/postgresql.conf" "${cfg.dataDir}/postgresql.conf"
             ${optionalString (cfg.recoveryConfig != null) ''
               ln -sfn "${pkgs.writeText "recovery.conf" cfg.recoveryConfig}" \
                 "${cfg.dataDir}/recovery.conf"