1 preCheckHooks
+=('postgresqlStart')
2 postCheckHooks
+=('postgresqlStop')
7 # Add default environment variable values
10 # - https://www.postgresql.org/docs/current/libpq-envars.html
13 # - only PGDATA: https://www.postgresql.org/docs/current/creating-cluster.html
15 if [[ "${PGDATA:-}" == "" ]]; then
16 PGDATA
="$NIX_BUILD_TOP/postgresql"
20 if [[ "${PGHOST:-}" == "" ]]; then
21 mkdir
-p "$NIX_BUILD_TOP/run/postgresql"
22 PGHOST
="$NIX_BUILD_TOP/run/postgresql"
26 if [[ "${PGUSER:-}" == "" ]]; then
31 if [[ "${PGDATABASE:-}" == "" ]]; then
36 if [[ "${postgresqlTestUserOptions:-}" == "" ]]; then
37 postgresqlTestUserOptions
="LOGIN"
40 if [[ "${postgresqlTestSetupSQL:-}" == "" ]]; then
41 postgresqlTestSetupSQL
="$(cat <<EOF
42 CREATE ROLE "$PGUSER" $postgresqlTestUserOptions;
43 CREATE DATABASE "$PGDATABASE" OWNER '$PGUSER';
48 if [[ "${postgresqlTestSetupCommands:-}" == "" ]]; then
49 postgresqlTestSetupCommands
='echo "$postgresqlTestSetupSQL" | PGUSER=postgres psql postgres'
52 if ! type initdb
>/dev
/null
; then
53 echo >&2 'initdb not found. Did you add postgresql to the nativeCheckInputs?'
56 echo 'initializing postgresql'
59 echo "$postgresqlExtraSettings" >>"$PGDATA/postgresql.conf"
62 echo "unix_socket_directories = '$NIX_BUILD_TOP/run/postgresql'" >>"$PGDATA/postgresql.conf"
64 # TCP ports can be a problem in some sandboxes,
65 # so we disable tcp listening by default
66 if ! [[ "${postgresqlEnableTCP:-}" = 1 ]]; then
67 echo "listen_addresses = ''" >>"$PGDATA/postgresql.conf"
70 echo 'starting postgresql'
71 eval "${postgresqlStartCommands:-pg_ctl start}"
73 echo 'setting up postgresql'
74 eval "$postgresqlTestSetupCommands"
76 runHook postgresqlTestSetupPost
81 echo 'stopping postgresql'