Skip to content

Instantly share code, notes, and snippets.

@SkyWriter
Forked from danbst/default.nix
Created February 10, 2024 21:19
Show Gist options
  • Save SkyWriter/2bd230154ba0553a5be47a9d5ab82240 to your computer and use it in GitHub Desktop.
Save SkyWriter/2bd230154ba0553a5be47a9d5ab82240 to your computer and use it in GitHub Desktop.
Proof-of-Concept running PostgreSQL tests inside Nix package build
with import <nixpkgs> { };
runCommand "some-test" {
buildInputs = [ postgresql ];
preCheck = ''
set -e
export PGDATA=$TMP/db
export PGHOST=$TMP/socketdir
mkdir $PGDATA $PGHOST
pg_ctl initdb
echo "unix_socket_directories = '$PGHOST'" >> $PGDATA/postgresql.conf
pg_ctl start &
trap "${procps}/bin/pkill postgres || true" EXIT
sleep 1
psql -d postgres -c "create database test"
'';
postCheck = ''
psql -d postgres -c "drop database test"
pg_ctl stop -m fast
'';
} ''
eval "$preCheck"
whoops some error happend during check phase
eval "$postCheck"
touch $out
''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment