add initdb command

This commit is contained in:
2025-03-16 00:47:41 +04:00
parent df17c8b0d5
commit a68ee5fe04

13
lib.nix
View File

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