Created
June 7, 2019 11:40
-
-
Save lightdiscord/7e72bcdc4424af2cea18702c05ad2a5f to your computer and use it in GitHub Desktop.
Postgresql inside nix-shell
This file contains hidden or 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> {}; | |
stdenv.mkDerivation { | |
name = "postgresql-inside-nixshell"; | |
buildInputs = [ | |
postgresql | |
]; | |
shellHook = '' | |
export PGDATA=$(mktemp -d) | |
export SOCKET_DIRECTORIES=$(mktemp -d) | |
initdb | |
echo "unix_socket_directories = '$SOCKET_DIRECTORIES'" >> $PGDATA/postgresql.conf | |
pg_ctl -l $PGDATA/logfile start | |
function end { | |
echo "Shutting down the database..." | |
pg_ctl stop | |
echo "Removing directories..." | |
rm -rf $PGDATAA $SOCKET_DIRECTORIES | |
} | |
trap end EXIT | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment