git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/postgresql: check config file syntax at build time
commit1b7ca69ecc47c807df21c1291c98fec0d4e294db authorSymphorien Gibol <symphorien+git@xlumurb.eu> dateSat 11 Jul 2020, 12:00 (6 years ago) parente0759a4
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
@@ -543,6 +543,14 @@ systemd.services.nginx.serviceConfig.ReadWritePaths = [ "/var/www" ];
543543 will have changed.
544544 </para>
545545 </listitem>
546+ <listitem>
547+ <para>
548+ The syntax of the PostgreSQL configuration file is now checked at build
549+ time. If your configuration includes a file inaccessible inside the build
550+ sandbox, set <varname>services.postgresql.checkConfig</varname> to
551+ <literal>false</literal>.
552+ </para>
553+ </listitem>
546554 <listitem>
547555 <para>
548556 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}";
@@ -309,6 +320,8 @@ in
309320 "/share/postgresql"
310321 ];
311322
323+ system.extraDependencies = lib.optional (cfg.checkConfig && pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) configFileCheck;
324+
312325 systemd.services.postgresql =
313326 { description = "PostgreSQL Server";
314327
@@ -332,7 +345,7 @@ in
332345 touch "${cfg.dataDir}/.first_startup"
333346 fi
334347
335− ln -sfn "${configFile}" "${cfg.dataDir}/postgresql.conf"
348+ ln -sfn "${configFile}/postgresql.conf" "${cfg.dataDir}/postgresql.conf"
336349 ${optionalString (cfg.recoveryConfig != null) ''
337350 ln -sfn "${pkgs.writeText "recovery.conf" cfg.recoveryConfig}" \
338351 "${cfg.dataDir}/recovery.conf"