fix postgres config

This commit is contained in:
2025-03-16 00:35:35 +04:00
parent fd3726ead2
commit 739830d352

61
lib.nix
View File

@@ -11,17 +11,17 @@ in
modules ? [ ],
}:
let
merged_config = lib.foldl' (acc: elem: acc // elem.config) config modules;
checks = lib.concatStringsSep "\n" (
lib.concatMap (
attrs:
lib.mapAttrsToList (k: v: ''
echo "Running ${k}"
${v}/bin/check
echo "Passed ${k}"
'') attrs.checks
) modules
);
merged_config = lib.foldl' (acc: elem: lib.recursiveUpdate acc elem) config modules;
# checks = lib.concatStringsSep "\n" (
# lib.concatMap (
# attrs:
# lib.mapAttrsToList (k: v: ''
# echo "Running ${k}"
# ${v}/bin/check
# echo "Passed ${k}"
# '') attrs.checks
# ) modules
# );
removeNullAndEmptyAttrs =
attrs:
let
@@ -48,15 +48,18 @@ in
)
);
in
pkgs.writeShellApplication {
inherit name;
text =
checks
+ ''
PC_CONFIG_FILES=${configFile} ${pkgs.process-compose}/bin/process-compose "$@"
'';
{
inherit configFile merged_config;
};
# pkgs.writeShellApplication {
# inherit name;
# text =
# checks
# + ''
# PC_CONFIG_FILES=${configFile} ${pkgs.process-compose}/bin/process-compose "$@"
#
# '';
# };
mkPostgres =
{
name,
@@ -64,6 +67,7 @@ in
config ? { },
extra_config ? '''',
package ? pkgs.postgresql,
data_dir ? ".data/",
...
}:
let
@@ -92,23 +96,22 @@ in
"'${lib.replaceStrings [ "'" ] [ "''" ] value}'"
else
builtins.toString value;
configFile = pkgs.writeTextDir "postgresql.conf" (
lib.concatStringsSep "\n" (
configFile = pkgs.writeTextFile {
name = "postgresql.conf";
text = lib.concatStringsSep "\n" (
lib.mapAttrsToList (n: v: "${n} = ${toStr v}") (
lib.filterAttrs (lib.const (x: x != null)) merged_config
)
)
);
configFileCheck = pkgs.writeShellApplication {
name = "check";
text = ''
${package}/bin/postgres -D${configFile} -C config_file
'';
};
in
# configFileCheck = pkgs.runCommand {} ''
# ${package}/bin/postgres -D${configFile} -C config_file
# touch $out
# '';
{
config.processes."${name}" = {
processes."${name}" = {
command = "${package}/bin/postgresql -D ${data_dir} --config-file ${configFile}";
};
checks."postgresql${name}" = configFileCheck;
};
}