-
Notifications
You must be signed in to change notification settings - Fork 1
/
shell.nix
49 lines (41 loc) · 1.16 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
let
pkgs = import <nixpkgs> {};
in pkgs.stdenv.mkDerivation {
name = "env";
buildInputs = [
(pkgs.yarn.override { nodejs = pkgs.nodejs-12_x; })
pkgs.postgresql_11
];
shellHook = ''
yarn
export LANG="en_US.UTF-8"
export PGDATA=$PWD/local-db
export DB_HOST=localhost
export DB_DATABASE=postgres
export DB_USER=postgres
export DB_PASSWORD=postgres
export DB_PORT=5435
export DB_URL=postgresql://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_DATABASE
if [ ! -d $PGDATA ];
then
echo 'Initializing postgresql database...'
touch pw.txt
echo $DB_PASSWORD >> pw.txt
initdb $PGDATA -U $DB_USER --pwfile=./pw.txt --auth=trust >/dev/null
rm pw.txt
pg_ctl -o "-p $DB_PORT" start
psql $DB_URL -f sql/init.pgsql
psql $DB_URL -f sql/seed.pgsql
else
pg_ctl -o "-p $DB_PORT" start
fi
trap "
pg_ctl stop
rm .env.local
" EXIT
echo "DATABASE_URL=$DB_URL" >> .env.local
'';
nobuild = ''
echo Do not run this derivation with nix-build, it can only be used with nix-shell
'';
}