rewrite parts of the script

This commit is contained in:
2025-03-17 11:31:35 +04:00
parent 2ce75022a7
commit d6e8ef7aed

19
lib.nix
View File

@@ -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}
'';