From c7d116be8721b52e202fc47e805e83dee4e98657 Mon Sep 17 00:00:00 2001 From: Nikkuss Date: Mon, 17 Mar 2025 13:36:32 +0400 Subject: [PATCH] fix script --- lib.nix | 55 +++++++++++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/lib.nix b/lib.nix index 226afea..56f26c9 100644 --- a/lib.nix +++ b/lib.nix @@ -108,37 +108,32 @@ in ) ); }; - setupScript = pkgs.writeShellApplication { - runtimeInputs = [ pkgs.makeWrapper ]; - name = "setup-postgres"; - text = '' - set -euo pipefail - export PATH=${package}/bin:${pkgs.coreutils}/bin - POSTGRES_RUN_INITIAL_SCRIPT="false" - if [[ ! -d "$PGDATA" ]]; then - initdb --no-instructions - POSTGRES_RUN_INITIAL_SCRIPT="true" - echo - echo "PostgreSQL initdb process completed" - echo - fi - substituteAllInPlace "$PGDATA"/postgresql.conf - cp ${configFile} "$PGDATA"/postgresql.conf - if [[ "$POSTGRES_RUN_INITIAL_SCRIPT" == "true" ]]; then - echo - echo "PostgreSQL is setting up the initial database" - echo - pg_ctl -w start -o "-c unix_socket_directories=$PGHOST -c listen_addresses= -p ${builtins.toString port}" - pg_ctl -m fast -w stop - else - echo - echo "Database directory exists. Skipping initialization" - echo - fi + setupScript = pkgs.writeShellScriptBin "setup-postgres" '' + set -euo pipefail + export PATH=${package}/bin:${pkgs.coreutils}/bin + POSTGRES_RUN_INITIAL_SCRIPT="false" + if [[ ! -d "$PGDATA" ]]; then + initdb --no-instructions + POSTGRES_RUN_INITIAL_SCRIPT="true" + echo + echo "PostgreSQL initdb process completed" + echo + fi + sed "s|@PGHOST|''${PGHOST}|g" ${configFile} > "$PGDATA"/postgresql.conf + if [[ "$POSTGRES_RUN_INITIAL_SCRIPT" == "true" ]]; then + echo + echo "PostgreSQL is setting up the initial database" + echo + pg_ctl -w start -o "-c unix_socket_directories=$PGHOST -c listen_addresses= -p ${builtins.toString port}" + pg_ctl -m fast -w stop + else + echo + echo "Database directory exists. Skipping initialization" + echo + fi - unset POSTGRES_RUN_INITIAL_SCRIPT - ''; - }; + unset POSTGRES_RUN_INITIAL_SCRIPT + ''; script = pkgs.writeShellApplication { name = "run-postgres";