Skip to content

Commit 6b206d7

Browse files
committed
modules/services/postgresql.nix: add startScript, earlyStartScript options
Signed-off-by: magic_rb <[email protected]>
1 parent ae75e02 commit 6b206d7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

modules/services/postgresql.nix

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ in
129129
'';
130130
};
131131

132+
startScript = lib.mkOption {
133+
type = lib.types.lines;
134+
description = ''
135+
PostgresSQL script to run on every startup.
136+
'';
137+
default = "";
138+
};
139+
140+
earlyStartScript = lib.mkOption {
141+
type = lib.types.lines;
142+
description = ''
143+
PostgresSQL script to run on every startup, very early.
144+
'';
145+
default = "";
146+
};
147+
148+
132149
ensureExtensions = lib.mkOption {
133150
type = with lib.types; attrsOf (listOf str);
134151
default = { };
@@ -405,12 +422,14 @@ in
405422
chpst -u postgres:postgres ${cfg.package}/bin/postgres &
406423
postgresql=$!
407424
408-
PSQL="chpst -u postgres:postgres ${cfg.package}/bin/psql --port=${cfg.port}"
425+
PSQL="chpst -u postgres:postgres ${cfg.package}/bin/psql --port=${cfg.port} -X"
409426
while ! $PSQL -d postgres -c "" 2> /dev/null ; do
410427
if ! kill -0 "$postgresql"; then exit 1; fi
411428
sleep 0.1
412429
done
413430
431+
$PSQL -f "${pkgs.writeText "postgres-start-early.sql" cfg.earlyStartScript}"
432+
414433
${lib.concatMapStrings
415434
(
416435
{ database, options }:
@@ -465,6 +484,8 @@ in
465484
rm -f "${cfg.dataDir}/.first_startup"
466485
fi
467486
487+
$PSQL -f "${pkgs.writeText "postgres-start.sql" cfg.startScript}"
488+
468489
wait $postgresql
469490
'';
470491
# END Copyright (c) 2003-2021 Eelco Dolstra and the Nixpkgs/NixOS contributors

0 commit comments

Comments
 (0)