Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion modules/services/postgresql.nix
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,23 @@ in
'';
};

startScript = lib.mkOption {
type = lib.types.lines;
description = ''
PostgresSQL script to run on every startup.
'';
default = "";
};

earlyStartScript = lib.mkOption {
type = lib.types.lines;
description = ''
PostgresSQL script to run on every startup, very early.
'';
default = "";
};


ensureExtensions = lib.mkOption {
type = with lib.types; attrsOf (listOf str);
default = { };
Expand Down Expand Up @@ -405,12 +422,14 @@ in
chpst -u postgres:postgres ${cfg.package}/bin/postgres &
postgresql=$!

PSQL="chpst -u postgres:postgres ${cfg.package}/bin/psql --port=${cfg.port}"
PSQL="chpst -u postgres:postgres ${cfg.package}/bin/psql --port=${cfg.port} -X"
while ! $PSQL -d postgres -c "" 2> /dev/null ; do
if ! kill -0 "$postgresql"; then exit 1; fi
sleep 0.1
done

$PSQL -f "${pkgs.writeText "postgres-start-early.sql" cfg.earlyStartScript}"

${lib.concatMapStrings
(
{ database, options }:
Expand Down Expand Up @@ -465,6 +484,8 @@ in
rm -f "${cfg.dataDir}/.first_startup"
fi

$PSQL -f "${pkgs.writeText "postgres-start.sql" cfg.startScript}"

wait $postgresql
'';
# END Copyright (c) 2003-2021 Eelco Dolstra and the Nixpkgs/NixOS contributors
Expand Down