From d6e8ef7aed082255efe08b5c238c753ea83bba8b Mon Sep 17 00:00:00 2001 From: Nikkuss Date: Mon, 17 Mar 2025 11:31:35 +0400 Subject: [PATCH] rewrite parts of the script --- lib.nix | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib.nix b/lib.nix index 129bc30..275ba4b 100644 --- a/lib.nix +++ b/lib.nix @@ -1,6 +1,7 @@ { pkgs }: let inherit (pkgs) lib; + runtime = ".compose"; in { mkWrapper = @@ -71,6 +72,7 @@ in ... }: let + runtimeDir = "${runtime}/${name}"; merged_config = ( if default_config then @@ -113,15 +115,24 @@ in export PATH=${package}/bin:${pkgs.coreutils}/bin POSTGRES_RUN_INITIAL_SCRIPT="false" if [[ ! -d "${data_dir}" ]]; then - echo "Database directory does not exist. Initializing" + + initdb -D ${data_dir} --no-instructions POSTGRES_RUN_INITIAL_SCRIPT="true" - ${package}/bin/initdb -D ${data_dir} --no-instructions + echo + echo "PostgreSQL initdb process completed" + echo fi cp ${configFile} ${data_dir}/postgresql.conf if [[ "$POSTGRES_RUN_INITIAL_SCRIPT" == "true" ]]; then - echo "Running initial script" + echo + echo "PostgreSQL is setting up the initial database" + echo + OLDPGHOST="$PGHOST" + 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 else echo echo "Database directory exists. Skipping initialization" @@ -135,7 +146,7 @@ in name = "run-postgres"; text = '' set -euo pipefail - mkdir -p ${lib.escapeShellArg data_dir} + mkdir -p ${lib.escapeShellArg runtimeDir} ${setupScript}/bin/setup-postgres exec ${package}/bin/postgres -D${data_dir} '';