2021-01-08 00:04:47 +01:00
|
|
|
{ pkgs ? import <nixpkgs> { } }:
|
|
|
|
|
|
|
|
with pkgs;
|
|
|
|
|
|
|
|
let
|
|
|
|
sql_file = "data/db.sql";
|
|
|
|
data_dir = "$(pwd)/.pgdata";
|
|
|
|
|
|
|
|
in mkShell {
|
|
|
|
buildInputs = [ postgresql ];
|
|
|
|
|
|
|
|
shellHook = ''
|
|
|
|
trap "kill 0" EXIT
|
|
|
|
export PGDATA="${data_dir}"
|
|
|
|
export PGHOST="${data_dir}"
|
|
|
|
|
|
|
|
if [ ! -d ${data_dir} ]; then
|
|
|
|
initdb --auth-local=trust --no-locale --encoding=UTF8
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! pg_ctl status; then
|
|
|
|
pg_ctl start -o "--unix_socket_directories=${data_dir} --listen_addresses='''"
|
|
|
|
fi
|
|
|
|
|
2021-02-08 01:16:31 +01:00
|
|
|
if [ ! -d ${data_dir} ]; then
|
|
|
|
psql -d postgres -f ${sql_file}
|
|
|
|
fi
|
|
|
|
|
2021-01-08 00:04:47 +01:00
|
|
|
alias psql='psql -d postgres'
|
2021-02-05 19:00:50 +01:00
|
|
|
alias nuke='rm -rf ${data_dir}'
|
2021-01-08 00:04:47 +01:00
|
|
|
'';
|
|
|
|
}
|