-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostgres.nix
40 lines (36 loc) · 1.56 KB
/
postgres.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
{ pgdata, dbport ? "5432" }:
let
pkgs = import <nixpkgs> {};
in
pkgs.mkShell {
packages = with pkgs; [ postgresql cowsay ];
shellHook = ''
export PGDATA=${pgdata}
fg_postgres() {
trap "pg_ctl -D $PGDATA stop && cowsay server stopped on $PGDATA:${dbport}" EXIT
if ! test -d $PGDATA
then
pg_ctl initdb -D $PGDATA
sed -i "s|^#port.*$|port = ${dbport}|" $PGDATA/postgresql.conf
fi
# These are only suitable for development.
HOST_COMMON="host\s\+all\s\+all"
sed -i "s|^$HOST_COMMON.*127.*$|host all all 0.0.0.0/0 trust|" $PGDATA/pg_hba.conf
sed -i "s|^$HOST_COMMON.*::1.*$|host all all ::/0 trust|" $PGDATA/pg_hba.conf
pg_ctl \
-D $PGDATA \
-l $PGDATA/postgres.log \
-o "-c unix_socket_directories='$PGDATA'" \
-o "-c listen_addresses='*'" \
-o "-c log_destination='stderr'" \
-o "-c logging_collector=on" \
-o "-c log_directory='log'" \
-o "-c log_filename='postgresql-%Y-%m-%d_%H%M%S.log'" \
-o "-c log_min_messages=info" \
-o "-c log_min_error_statement=info" \
-o "-c log_connections=on" \
start
tail -F $PGDATA/postgres.log
}
'';
}