-
-
Save gusmacaulay/9dc5793439750912458f3c6a8945de7d to your computer and use it in GitHub Desktop.
Postgresql/Postgis inside nix-shell with sqitch and default postgres user
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 = [ | |
glibcLocales | |
(pkgs.postgresql.withPackages (p: [ p.postgis ])) | |
sqitchPg | |
pgcli | |
]; | |
shellHook = '' | |
export PGDATA="$PWD/db" | |
export SOCKET_DIRECTORIES="$PWD/sockets" | |
mkdir $SOCKET_DIRECTORIES | |
initdb | |
echo "unix_socket_directories = '$SOCKET_DIRECTORIES'" >> $PGDATA/postgresql.conf | |
pg_ctl -l $PGDATA/logfile start | |
createuser postgres --createdb -h localhost | |
function end { | |
echo "Shutting down the database..." | |
pg_ctl stop | |
echo "Removing directories..." | |
rm -rf $PGDATA $SOCKET_DIRECTORIES | |
} | |
trap end EXIT | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This shell.nix runs up a postgresql instance in a nix-shell, it solves issue with postgis package working with postgresql, and it solves issue with locale settings which means it can run on other host OS' eg. ubuntu,debian