nixpkgs/pkgs/by-name/po/postgresqlTestHook/postgresql-test-hook.sh
aleksana 571c71e6f7 treewide: migrate packages to pkgs/by-name, take 1
We are migrating packages that meet below requirements:

1. using `callPackage`
2. called path is a directory
3. overriding set is empty (`{ }`)
4. not containing path expressions other than relative path (to
makenixpkgs-vet happy)
5. not referenced by nix files outside of the directory, other
than`pkgs/top-level/all-packages.nix`
6. not referencing nix files outside of the directory
7. not referencing `default.nix` (since it's changed to `package.nix`)
8. `outPath` doesn't change after migration

The tool is here: https://github.com/Aleksanaa/by-name-migrate.
2024-11-09 20:04:51 +08:00

84 lines
2.0 KiB
Bash

preCheckHooks+=('postgresqlStart')
postCheckHooks+=('postgresqlStop')
postgresqlStart() {
# Add default environment variable values
#
# Client variables:
# - https://www.postgresql.org/docs/current/libpq-envars.html
#
# Server variables:
# - only PGDATA: https://www.postgresql.org/docs/current/creating-cluster.html
if [[ "${PGDATA:-}" == "" ]]; then
PGDATA="$NIX_BUILD_TOP/postgresql"
fi
export PGDATA
if [[ "${PGHOST:-}" == "" ]]; then
mkdir -p "$NIX_BUILD_TOP/run/postgresql"
PGHOST="$NIX_BUILD_TOP/run/postgresql"
fi
export PGHOST
if [[ "${PGUSER:-}" == "" ]]; then
PGUSER="test_user"
fi
export PGUSER
if [[ "${PGDATABASE:-}" == "" ]]; then
PGDATABASE="test_db"
fi
export PGDATABASE
if [[ "${postgresqlTestUserOptions:-}" == "" ]]; then
postgresqlTestUserOptions="LOGIN"
fi
if [[ "${postgresqlTestSetupSQL:-}" == "" ]]; then
postgresqlTestSetupSQL="$(cat <<EOF
CREATE ROLE "$PGUSER" $postgresqlTestUserOptions;
CREATE DATABASE "$PGDATABASE" OWNER '$PGUSER';
EOF
)"
fi
if [[ "${postgresqlTestSetupCommands:-}" == "" ]]; then
postgresqlTestSetupCommands='echo "$postgresqlTestSetupSQL" | PGUSER=postgres psql postgres'
fi
if ! type initdb >/dev/null; then
echo >&2 'initdb not found. Did you add postgresql to the nativeCheckInputs?'
false
fi
echo 'initializing postgresql'
initdb -U postgres
echo "$postgresqlExtraSettings" >>"$PGDATA/postgresql.conf"
# Move the socket
echo "unix_socket_directories = '$NIX_BUILD_TOP/run/postgresql'" >>"$PGDATA/postgresql.conf"
# TCP ports can be a problem in some sandboxes,
# so we disable tcp listening by default
if ! [[ "${postgresqlEnableTCP:-}" = 1 ]]; then
echo "listen_addresses = ''" >>"$PGDATA/postgresql.conf"
fi
echo 'starting postgresql'
eval "${postgresqlStartCommands:-pg_ctl start}"
echo 'setting up postgresql'
eval "$postgresqlTestSetupCommands"
runHook postgresqlTestSetupPost
}
postgresqlStop() {
echo 'stopping postgresql'
pg_ctl stop
}