test process-comose postgres + check functionality
This commit is contained in:
68
lib.nix
68
lib.nix
@@ -8,8 +8,20 @@ in
|
|||||||
config,
|
config,
|
||||||
name,
|
name,
|
||||||
enableTui ? false,
|
enableTui ? false,
|
||||||
|
modules ? [ ],
|
||||||
}:
|
}:
|
||||||
let
|
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}
|
||||||
|
echo "Passed ${k}"
|
||||||
|
'') attrs.checks
|
||||||
|
) modules
|
||||||
|
);
|
||||||
removeNullAndEmptyAttrs =
|
removeNullAndEmptyAttrs =
|
||||||
attrs:
|
attrs:
|
||||||
let
|
let
|
||||||
@@ -29,7 +41,7 @@ in
|
|||||||
};
|
};
|
||||||
configFile = toPCJson name (
|
configFile = toPCJson name (
|
||||||
removeNullAndEmptyAttrs (
|
removeNullAndEmptyAttrs (
|
||||||
config
|
merged_config
|
||||||
// {
|
// {
|
||||||
is_tui_disabled = !enableTui;
|
is_tui_disabled = !enableTui;
|
||||||
}
|
}
|
||||||
@@ -39,16 +51,64 @@ in
|
|||||||
pkgs.writeShellApplication {
|
pkgs.writeShellApplication {
|
||||||
inherit name;
|
inherit name;
|
||||||
text = ''
|
text = ''
|
||||||
|
${checks}
|
||||||
PC_CONFIG_FILES=${configFile} ${pkgs.process-compose}/bin/process-compose "$@"
|
PC_CONFIG_FILES=${configFile} ${pkgs.process-compose}/bin/process-compose "$@"
|
||||||
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
mkPostgres =
|
mkPostgres =
|
||||||
{
|
{
|
||||||
default_config ? false,
|
name,
|
||||||
|
default_config ? true,
|
||||||
|
config ? { },
|
||||||
|
extra_config ? '''',
|
||||||
|
package ? pkgs.postgresql,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
in
|
merged_config =
|
||||||
{ };
|
(
|
||||||
|
if default_config then
|
||||||
|
{
|
||||||
|
listen_addresses = "localhost";
|
||||||
|
port = 5432;
|
||||||
|
shared_buffers = "128MB";
|
||||||
|
worker_mem = "4M";
|
||||||
|
logging_collector = "off";
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ }
|
||||||
|
)
|
||||||
|
// config;
|
||||||
|
toStr =
|
||||||
|
value:
|
||||||
|
if true == value then
|
||||||
|
"yes"
|
||||||
|
else if false == value then
|
||||||
|
"no"
|
||||||
|
else if lib.isString value then
|
||||||
|
"'${lib.replaceStrings [ "'" ] [ "''" value ]}'"
|
||||||
|
else
|
||||||
|
builtins.toString value;
|
||||||
|
configFile = pkgs.writeTextDir "postgresql.conf" (
|
||||||
|
lib.concatStringSep "\n" (
|
||||||
|
lib.mapAttrsToList (n: v: "${n} = ${toStr v}") (lib.filterAttrs (
|
||||||
|
lib.const (x: x != null)
|
||||||
|
)) merged_config
|
||||||
|
)
|
||||||
|
);
|
||||||
|
configFileCheck = pkgs.writeShellScript {
|
||||||
|
name = "postgresql-config-check-${name}";
|
||||||
|
text = ''
|
||||||
|
${package}/bin/postgres -D${configFile} -C config_file
|
||||||
|
touch $out
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
config.processes."${name}" = {
|
||||||
|
};
|
||||||
|
checks."postgresql${name}" = configFileCheck;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user