Skip to content

Instantly share code, notes, and snippets.

@lightdiscord
Created June 7, 2019 11:40
Show Gist options
  • Save lightdiscord/7e72bcdc4424af2cea18702c05ad2a5f to your computer and use it in GitHub Desktop.
Save lightdiscord/7e72bcdc4424af2cea18702c05ad2a5f to your computer and use it in GitHub Desktop.
Postgresql inside nix-shell
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