git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #92929 from symphorien/postgresql-check-config-file

nixos/postgresql: check config file syntax at build time

commitfe0e0afbc0fbf1d1f71577a38a11c1eb7f63745e authorGuillaume Girol <symphorien@users.noreply.github.com> dateFri 2 Apr 2021, 16:27 (6 years ago) parent5e237d61b7ca69
2 files changed+23−2
nixos/doc/manual/release-notes/rl-2009.xml+8 nixos/modules/services/databases/postgresql.nix+15−2
nixos/doc/manual/release-notes/rl-2009.xml+8
@@ -1017,6 +1017,14 @@ systemd.services.nginx.serviceConfig.ProtectHome = "read-only";
10171017 will have changed.
10181018 </para>
10191019 </listitem>
1020+ <listitem>
1021+ <para>
1022+ The syntax of the PostgreSQL configuration file is now checked at build
1023+ time. If your configuration includes a file inaccessible inside the build
1024+ sandbox, set <varname>services.postgresql.checkConfig</varname> to
1025+ <literal>false</literal>.
1026+ </para>
1027+ </listitem>
10201028 <listitem>
10211029 <para>
10221030 The rkt module has been removed, it was archived by upstream.
nixos/modules/services/databases/postgresql.nix+15−2
@@ -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"