Skip to content

Instantly share code, notes, and snippets.

@danbst
Created July 13, 2018 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danbst/bc21adf05ef7fd084fb85ed927d928c8 to your computer and use it in GitHub Desktop.
Save danbst/bc21adf05ef7fd084fb85ed927d928c8 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