Created
July 13, 2018 07:59
-
-
Save danbst/bc21adf05ef7fd084fb85ed927d928c8 to your computer and use it in GitHub Desktop.
Proof-of-Concept running PostgreSQL tests inside Nix package build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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