postgres_migration/shell.nix

37 lines
812 B
Nix
Raw Normal View History

2021-02-05 20:14:43 +01:00
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
let
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-10 01:26:54 +01:00
buildInputs = [ postgresql python27 python27Packages.virtualenv ];
2021-02-05 20:14:43 +01:00
shellHook = ''
trap "kill 0" EXIT
export PGDATA="${data_dir}"
export PGHOST="${data_dir}"
2021-02-05 20:14:43 +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
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
alias psql='psql -d postgres'
alias nuke='rm -rf ${data_dir}'
2021-02-10 01:26:54 +01:00
# Workaround to use pip
SOURCE_DATE_EPOCH=$(date +%s)
virtualenv .venv
export PATH=$PWD/.venv/bin:$PATH
pip install etlalchemy
pip install psycopg2
2021-02-05 20:14:43 +01:00
'';
}