Skip to content

Commit

Permalink
services.mysqlBackup: allow gzip to use compressionLevel too
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed Dec 31, 2024
1 parent fba19a8 commit d28fa69
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions nixos/modules/services/backup/mysql-backup.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ let
validCompressionLevels = {
zstd = range: 1 <= range && range <= 19;
xz = range: 0 <= range && range <= 9;
gzip = range: false; # gzip doesn't use compressionLevel
gzip = range: 1 <= range && range <= 9;
};

compressionCmd =
let
compressionLevelFlag =
if cfg.compressionLevel != null then "-${toString cfg.compressionLevel}" else "";
compressionLevelFlag = lib.optionalString (cfg.compressionLevel != null) (
"-" + toString cfg.compressionLevel
);
in
{
gzip = "${pkgs.gzip}/bin/gzip -c ${cfg.gzipOptions}";
gzip = "${pkgs.gzip}/bin/gzip -c ${cfg.gzipOptions} ${compressionLevelFlag}";
xz = "${pkgs.xz}/bin/xz -z -c ${compressionLevelFlag} -";
zstd = "${pkgs.zstd}/bin/zstd ${compressionLevelFlag} -";
}
Expand Down Expand Up @@ -95,10 +96,10 @@ in
type = lib.types.nullOr lib.types.int;
default = null;
description = ''
Compression level to use for zstd or xz.
Compression level to use for gzip, zstd or xz.
For gzip: 1-9 (note: if compression level is also specified in gzipOptions, the gzipOptions value will be overwritten)
For zstd: 1-19
For xz: 0-9
Ignored for gzip (use gzipOptions instead)
'';
};

Expand Down Expand Up @@ -140,6 +141,7 @@ in
description = ''
Command line options to use when invoking `gzip`.
Only used when compression is set to "gzip".
If compression level is specified both here and in compressionLevel, the compressionLevel value will take precedence.
'';
};
};
Expand All @@ -156,7 +158,7 @@ in
rangeMsg = {
"zstd" = "zstd compression level must be between 1 and 19";
"xz" = "xz compression level must be between 0 and 9";
"gzip" = "gzip does not support compression level option, use gzipOptions instead";
"gzip" = "gzip compression level must be between 1 and 9";
};
in
rangeMsg.${cfg.compression};
Expand Down

0 comments on commit d28fa69

Please sign in to comment.