nixos/postgresql-backup: do not enable assertions when module is disabled (#437168)
This commit is contained in:
@@ -152,45 +152,48 @@ in
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkMerge [
|
config = lib.mkIf cfg.enable (
|
||||||
{
|
lib.mkMerge [
|
||||||
assertions = [
|
{
|
||||||
{
|
assertions = [
|
||||||
assertion = cfg.backupAll -> cfg.databases == [ ];
|
|
||||||
message = "config.services.postgresqlBackup.backupAll cannot be used together with config.services.postgresqlBackup.databases";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
assertion =
|
|
||||||
cfg.compression == "none"
|
|
||||||
|| (cfg.compression == "gzip" && cfg.compressionLevel >= 1 && cfg.compressionLevel <= 9)
|
|
||||||
|| (cfg.compression == "zstd" && cfg.compressionLevel >= 1 && cfg.compressionLevel <= 19);
|
|
||||||
message = "config.services.postgresqlBackup.compressionLevel must be set between 1 and 9 for gzip and 1 and 19 for zstd";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
(lib.mkIf cfg.enable {
|
|
||||||
systemd.tmpfiles.rules = [
|
|
||||||
"d '${cfg.location}' 0700 postgres - - -"
|
|
||||||
];
|
|
||||||
})
|
|
||||||
(lib.mkIf (cfg.enable && cfg.backupAll) {
|
|
||||||
systemd.services.postgresqlBackup = postgresqlBackupService "all" "pg_dumpall ${cfg.pgdumpOptions}";
|
|
||||||
})
|
|
||||||
(lib.mkIf (cfg.enable && !cfg.backupAll) {
|
|
||||||
systemd.services = lib.listToAttrs (
|
|
||||||
map (
|
|
||||||
db:
|
|
||||||
let
|
|
||||||
cmd = "pg_dump ${cfg.pgdumpOptions} ${db}";
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
name = "postgresqlBackup-${db}";
|
assertion = cfg.backupAll -> cfg.databases == [ ];
|
||||||
value = postgresqlBackupService db cmd;
|
message = "config.services.postgresqlBackup.backupAll cannot be used together with config.services.postgresqlBackup.databases";
|
||||||
}
|
}
|
||||||
) cfg.databases
|
{
|
||||||
);
|
assertion =
|
||||||
})
|
cfg.compression == "none"
|
||||||
];
|
|| (cfg.compression == "gzip" && cfg.compressionLevel >= 1 && cfg.compressionLevel <= 9)
|
||||||
|
|| (cfg.compression == "zstd" && cfg.compressionLevel >= 1 && cfg.compressionLevel <= 19);
|
||||||
|
message = "config.services.postgresqlBackup.compressionLevel must be set between 1 and 9 for gzip and 1 and 19 for zstd";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
systemd.tmpfiles.rules = [
|
||||||
|
"d '${cfg.location}' 0700 postgres - - -"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
(lib.mkIf cfg.backupAll {
|
||||||
|
systemd.services.postgresqlBackup = postgresqlBackupService "all" "pg_dumpall ${cfg.pgdumpOptions}";
|
||||||
|
})
|
||||||
|
|
||||||
|
(lib.mkIf (!cfg.backupAll) {
|
||||||
|
systemd.services = lib.listToAttrs (
|
||||||
|
map (
|
||||||
|
db:
|
||||||
|
let
|
||||||
|
cmd = "pg_dump ${cfg.pgdumpOptions} ${db}";
|
||||||
|
in
|
||||||
|
{
|
||||||
|
name = "postgresqlBackup-${db}";
|
||||||
|
value = postgresqlBackupService db cmd;
|
||||||
|
}
|
||||||
|
) cfg.databases
|
||||||
|
);
|
||||||
|
})
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
meta.maintainers = with lib.maintainers; [ Scrumplex ];
|
meta.maintainers = with lib.maintainers; [ Scrumplex ];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user