diff --git a/flake.nix b/flake.nix index 5bfea89..62e839a 100644 --- a/flake.nix +++ b/flake.nix @@ -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; diff --git a/pkgs/compress-drv-tests.nix b/pkgs/compress-drv-tests.nix new file mode 100644 index 0000000..5620126 --- /dev/null +++ b/pkgs/compress-drv-tests.nix @@ -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 + '' diff --git a/pkgs/compress-drv.nix b/pkgs/compress-drv.nix index 290a717..ce5248f 100644 --- a/pkgs/compress-drv.nix +++ b/pkgs/compress-drv.nix @@ -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- :: String + - compressor- :: 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. diff --git a/statix.toml b/statix.toml index c2c0666..4ac04ee 100644 --- a/statix.toml +++ b/statix.toml @@ -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"]