From f429bb2ab1ecf9ec3c57dcad4b77eed251dec788 Mon Sep 17 00:00:00 2001 From: Nikkuss Date: Mon, 17 Mar 2025 12:25:01 +0400 Subject: [PATCH] fix script --- lib.nix | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/lib.nix b/lib.nix index 8cce73b..8703950 100644 --- a/lib.nix +++ b/lib.nix @@ -115,9 +115,8 @@ in set -euo pipefail export PATH=${package}/bin:${pkgs.coreutils}/bin POSTGRES_RUN_INITIAL_SCRIPT="false" - if [[ ! -d "${data_dir}" ]]; then - - initdb -D ${data_dir} --no-instructions + if [[ ! -d "$PGDATA" ]]; then + initdb --no-instructions POSTGRES_RUN_INITIAL_SCRIPT="true" echo echo "PostgreSQL initdb process completed" @@ -128,16 +127,8 @@ in echo echo "PostgreSQL is setting up the initial database" echo - if [[ -z "''${PGHOST+x}" ]]; then - OLDPGHOST="" - else - OLDPGHOST="$PGHOST" - fi - PGHOST=${lib.escapeShellArg runtimeDir} - pg_ctl -D "${data_dir}" -w start -o "-c unix_socket_directories=${data_dir} -c listen_addresses= -p ${builtins.toString port}" - pg_ctl -D "${data_dir}" -m fast -w stop - PGHOST="$OLDPGHOST" - unset OLDPGHOST + pg_ctl -w start -o "-c unix_socket_directories=${data_dir} -c listen_addresses= -p ${builtins.toString port}" + pg_ctl -m fast -w stop else echo echo "Database directory exists. Skipping initialization" @@ -151,9 +142,10 @@ in name = "run-postgres"; text = '' set -euo pipefail + export PGDATA=${data_dir} PGHOST=${runtimeDir} PGPORT=${builtins.toString port} mkdir -p ${lib.escapeShellArg runtimeDir} ${setupScript}/bin/setup-postgres - exec ${package}/bin/postgres -D${data_dir} + exec ${package}/bin/postgres ''; }; in