From a68ee5fe04d10ba8eb6f106deb31e1caae83fdf0 Mon Sep 17 00:00:00 2001 From: Nikkuss Date: Sun, 16 Mar 2025 00:47:41 +0400 Subject: [PATCH] add initdb command --- lib.nix | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib.nix b/lib.nix index 072bfed..eeaaefc 100644 --- a/lib.nix +++ b/lib.nix @@ -102,6 +102,17 @@ in ) ); }; + script = pkgs.writeShellApplication { + name = "run-postgres"; + text = '' + if [! -d "${data_dir}"]; then + echo "Database directory does not exist. Initializing" + initdb -D ${data_dir} + fi + ${package}/bin/postgres -D ${data_dir} --config-file ${configFile} + + ''; + }; in # configFileCheck = pkgs.runCommand {} '' # ${package}/bin/postgres -D${configFile} -C config_file @@ -109,7 +120,7 @@ in # ''; { processes."${name}" = { - command = "${package}/bin/postgres -D ${data_dir} --config-file ${configFile}"; + command = "${script}/bin/run-postgres"; }; }; }