compress-drv-tests

This commit is contained in:
Motiejus Jakštys 2024-02-24 19:43:19 +02:00
parent b6724ef10e
commit 4a74dc2ac1
4 changed files with 54 additions and 4 deletions

View File

@ -310,6 +310,11 @@
statix.enable = true;
};
};
compress-drv-tests = let
pkgs = import nixpkgs {inherit system;};
in
pkgs.callPackage ./pkgs/compress-drv-tests.nix {};
}
)
deploy-rs.lib;

View File

@ -0,0 +1,29 @@
{
gzip,
callPackage,
runCommandNoCC,
}: let
compressDrv = (callPackage ./compress-drv.nix {}).compressDrv;
example = runCommandNoCC "sample-drv" {} ''
mkdir $out
echo 1 > $out/1.txt
touch $out/2.png
'';
drv = compressDrv example {
formats = ["txt"];
compressors = ["gz"];
compressor-gz = "${gzip}/bin/gzip --force --keep --fast {}";
};
in
runCommandNoCC "test-compressDrv" {} ''
set -ex
find ${drv}
test -h ${drv}/1.txt
test -f ${drv}/1.txt.gz
cmp ${drv}/1.txt <(${gzip}/bin/zcat ${drv}/1.txt.gz)
test -h ${drv}/2.png
test ! -a ${drv}/2.png.gz
mkdir $out
''

View File

@ -26,6 +26,7 @@
find -L $out -type f -regextype posix-extended \
-iregex '.*\.(${formatsbar})' | \
${builtins.concatStringsSep " | \\\n " compressCommands}
find $out/
'';
in {
/*
@ -46,7 +47,7 @@ in {
Example: ["gz" "zstd"]
- compressor-<COMPRESSOR> :: String
- compressor-<EXTENSION> :: String
Map a desired extension (e.g. `gz`) to a compress program.
@ -55,14 +56,19 @@ in {
xargs -I{} -n1 ${prog}
Example:
Compressor must:
- read symlinks (thus --force is needed to gzip, zstd, xz).
- keep the original file in place (--keep).
compressor-xz = "${xz}/bin/xz --keep {}";
Example compressor:
compressor-xz = "${xz}/bin/xz --force --keep {}";
See compressDrvWeb, which is a wrapper on top of compressDrv, for broader
use examples.
*/
inherit (compressDrv);
compressDrv = compressDrv;
/*
compressDrvWeb compresses a derivation for "web server" usage.

View File

@ -1 +1,11 @@
ignore = ['modules/base/boot']
# If the attrset has an optional field, `inherit` will not inherit it:
# compressDrvWeb = drv: {
# compressors ? ["gz" "br"],
# ...
# } @ args:
# compressDrv drv {
# inherit (compressors) <<- function 'compressDrv' called without required argument 'compressors'
# }
disabled = ["manual_inherit", "manual_inherit_from"]