nixos/repart: add zstd-seekable compression algorithm

The seekable format splits compressed data into a series of independent
frames, each of which can be decompressed individually. This allows to
distribute images in smaller chunks and allows image downloads to be
paused and resumed later from the same point.

Seekable archives as a whole can be decompressed with any regular zstd
decompressor. However, partial decompression requires to know the
starting position of the desired frame, which can be extracted from a
skippable frame (aka seektable) that is appended to the compressed data.
This commit is contained in:
Robert Rose 2025-02-26 08:47:06 +01:00
parent 10f9a88c05
commit 119b75c310
3 changed files with 11 additions and 10 deletions

View file

@ -24,6 +24,7 @@
# compression tools
, zstd
, xz
, zeekstd
# arguments
, name
@ -89,11 +90,13 @@ let
compressionPkg = {
"zstd" = zstd;
"xz" = xz;
"zstd-seekable" = zeekstd;
}."${compression.algorithm}";
compressionCommand = {
"zstd" = "zstd --no-progress --threads=$NIX_BUILD_CORES -${toString compression.level}";
"xz" = "xz --keep --verbose --threads=$NIX_BUILD_CORES -${toString compression.level}";
"zstd-seekable" = "zeekstd --quiet --max-frame-size 2M --compression-level ${toString compression.level}";
}."${compression.algorithm}";
in
stdenvNoCC.mkDerivation (finalAttrs:

View file

@ -113,7 +113,7 @@ in
enable = lib.mkEnableOption "Image compression";
algorithm = lib.mkOption {
type = lib.types.enum [ "zstd" "xz" ];
type = lib.types.enum [ "zstd" "xz" "zstd-seekable" ];
default = "zstd";
description = "Compression algorithm";
};
@ -274,6 +274,7 @@ in
{
"zstd" = ".zst";
"xz" = ".xz";
"zstd-seekable" = ".zst";
}."${cfg.compression.algorithm}";
makeClosure = paths: pkgs.closureInfo { rootPaths = paths; };
@ -298,6 +299,7 @@ in
level = lib.mkOptionDefault {
"zstd" = 3;
"xz" = 3;
"zstd-seekable" = 3;
}."${cfg.compression.algorithm}";
};

View file

@ -3,30 +3,26 @@
lib,
rustPlatform,
}:
let
version = "0.2.2";
in
rustPlatform.buildRustPackage {
rustPlatform.buildRustPackage (finalAttrs: {
pname = "zeekstd";
inherit version;
version = "0.2.2";
src = fetchFromGitHub {
owner = "rorosen";
repo = "zeekstd";
tag = "v${version}";
tag = "v${finalAttrs.version}";
hash = "sha256-Blyp5GpnytB3S4k6lp2fAwXueaUtXqPW+WLEmFNPZc0=";
};
useFetchCargoVendor = true;
cargoHash = "sha256-bbl0zHxd2HYkctX029mtxDciC2tnPVTlHxYyetmtuw0=";
stripAllList = [ "bin" ];
meta = {
description = "CLI tool that works with the zstd seekable format";
homepage = "https://github.com/rorosen/zeekstd";
changelog = "https://github.com/rorosen/zeekstd/releases/tag/v${version}";
changelog = "https://github.com/rorosen/zeekstd/releases/tag/v${finalAttrs.version}";
license = lib.licenses.bsd2;
maintainers = [ lib.maintainers.rorosen ];
mainProgram = "zeekstd";
};
}
})