Add postgreSQL initiation scripts to flake.nix

This commit is contained in:
Leo 2026-08-22 16:37:57 +03:00
parent fe0363746b
commit 4d856d3fd9
2 changed files with 18 additions and 1 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@ main
tmp/ tmp/
build-errors.log build-errors.log
result result
.devdata/

View file

@ -12,7 +12,7 @@
system: system:
let let
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
go = pkgs.go_1_24; go = pkgs.go_1_27;
in in
{ {
packages.default = pkgs.buildGoModule { packages.default = pkgs.buildGoModule {
@ -60,6 +60,22 @@
shellHook = '' shellHook = ''
echo "go-backend dev shell — $(go version)" echo "go-backend dev shell — $(go version)"
export PGDATA="$PWD/.devdata/pgdata"
export PGHOST="$PWD/.devdata/pgsocket"
mkdir -p "$PGHOST"
if [ ! -d "$PGDATA" ]; then
echo "Initializing Postgres data dir..."
initdb --auth=trust --no-locale --encoding=UTF8 -U postgres >/dev/null
fi
pg_ctl status >/dev/null 2>&1 || pg_ctl start -l "$PWD/.devdata/pg.log" -o "-k $PGHOST -h 127.0.0.1 -p 5432"
createdb -U postgres -h 127.0.0.1 backend_template 2>/dev/null || true
alias pg_stop="pg_ctl stop"
''; '';
}; };