fix postgres config

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

63
lib.nix
View File

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