Add PostgreSQL environment
This commit is contained in:
parent
cfbdd40ce3
commit
5ace56e9d8
|
@ -0,0 +1,28 @@
|
|||
{ 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
|
||||
|
||||
psql -d postgres -f ${sql_file}
|
||||
alias psql='psql -d postgres'
|
||||
'';
|
||||
}
|
Loading…
Reference in New Issue