2021-02-05 20:14:43 +01:00
|
|
|
{ pkgs ? import <nixpkgs> { } }:
|
|
|
|
|
|
|
|
with pkgs;
|
|
|
|
|
|
|
|
let
|
2021-02-09 15:17:02 +01:00
|
|
|
sql_file = "psql_creation.sql";
|
|
|
|
data_dir = "$(pwd)/.pgdata";
|
|
|
|
origin = "databases/odyfo.db";
|
2021-02-05 20:14:43 +01:00
|
|
|
|
|
|
|
in mkShell {
|
2021-02-09 15:17:02 +01:00
|
|
|
buildInputs = [ postgresql sqlite ];
|
2021-02-05 20:14:43 +01:00
|
|
|
|
|
|
|
shellHook = ''
|
|
|
|
trap "kill 0" EXIT
|
2021-02-09 15:17:02 +01:00
|
|
|
export PGDATA="${data_dir}"
|
|
|
|
export PGHOST="${data_dir}"
|
2021-02-05 20:14:43 +01:00
|
|
|
|
2021-02-09 15:17:02 +01:00
|
|
|
if [ ! -d ${data_dir} ]; then
|
2021-02-05 20:14:43 +01:00
|
|
|
initdb --auth-local=trust --no-locale --encoding=UTF8
|
|
|
|
fi
|
|
|
|
|
2021-02-05 21:16:35 +01:00
|
|
|
if ! pg_ctl status; then
|
2021-02-09 15:17:02 +01:00
|
|
|
pg_ctl start -o "--unix_socket_directories=${data_dir} --listen_addresses='''"
|
2021-02-05 21:16:35 +01:00
|
|
|
fi
|
2021-02-05 20:14:43 +01:00
|
|
|
|
2021-02-09 15:17:02 +01:00
|
|
|
psql -d postgres -f ${sql_file}
|
2021-02-08 01:34:54 +01:00
|
|
|
|
2021-02-05 20:14:43 +01:00
|
|
|
alias psql='psql -d postgres'
|
2021-02-09 15:17:02 +01:00
|
|
|
alias nuke='rm -rf ${data_dir}'
|
|
|
|
|
2021-02-05 20:14:43 +01:00
|
|
|
'';
|
|
|
|
}
|