From f5ab052719bf5499a76ea15ec8aead953f3d3788 Mon Sep 17 00:00:00 2001 From: Nikkuss Date: Mon, 17 Mar 2025 13:38:21 +0400 Subject: [PATCH] fix script --- lib.nix | 56 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/lib.nix b/lib.nix index 56f26c9..3f7214f 100644 --- a/lib.nix +++ b/lib.nix @@ -108,32 +108,38 @@ in ) ); }; - 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 + setupScript = pkgs.writeShellApplication { + name = "setup-postgres"; + runtimeInputs = [ + package + pkgs.coreutils + pkgs.gnused + ]; + text = '' + 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";