-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell.nix
51 lines (47 loc) · 1.55 KB
/
shell.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
with import ./nix/pkgs.nix {};
let merged-openssl = symlinkJoin { name = "merged-openssl"; paths = [ openssl.out openssl.dev ]; };
in stdenv.mkDerivation rec {
name = "rust-env";
env = buildEnv { name = name; paths = buildInputs; };
buildInputs = [
rustup
clang
llvm
llvmPackages.libclang
openssl
cacert
#podman-compose
docker-compose
postgresql_11
];
shellHook = ''
export LIBCLANG_PATH="${llvmPackages.libclang}/lib"
export OPENSSL_DIR="${merged-openssl}"
echo "Deploying local PostgreSQL"
export PG_DATA=./pgsql-data
export PG_PORT=5437
if [ ! -d "$PG_DATA" ]; then
initdb $PG_DATA --auth=trust
echo "port = $PG_PORT" >> $PG_DATA/postgresql.conf
echo "unix_socket_directories = '$PWD'" >> $PG_DATA/postgresql.conf
pg_ctl start -D$PG_DATA -l postgresql.log
psql --host=$PWD -p$PG_PORT -d postgres -c "create role \"dividator\" with login createdb password 'dividator';"
psql --host=$PWD -p$PG_PORT -d postgres -c "create database \"dividator\" owner \"dividator\";"
export DATABASE_URL=postgres://dividator:[email protected]:$PG_PORT/dividator
cargo run --bin migrator
#for f in ./dividator/migrations/*.sql
#do
# echo "Applying $f"
# psql --host=$PWD -p$PG_PORT -U dividator -d dividator -f $f
#done
else
pg_ctl start -D$PG_DATA -l postgresql.log
fi
function finish {
pg_ctl stop -D$PG_DATA
}
trap finish EXIT
export DATABASE_URL=postgres://dividator:[email protected]:$PG_PORT/dividator
echo "Local database accessible by $DATABASE_URL"
'';
}