compress-drv: allow passing extra arguments to find

This is useful for eg. nextcloud to prevent compressing thousands of
later unused files which are actually not used by the web server.
This commit is contained in:
Sandro Jäckel 2024-08-06 17:58:13 +02:00
parent 0ca4bfa700
commit 4cc5dee048
No known key found for this signature in database
GPG Key ID: 3AF5A43A3EECC2E5
2 changed files with 19 additions and 3 deletions

View File

@ -9,6 +9,12 @@
: List of file extensions to compress. Example: `["txt" "svg" "xml"]`.
`extraFindOperands` (String)
: Extra command line parameters to pass to the find command.
This can be used to exclude certain files.
For example: `-not -iregex ".*(\/apps\/.*\/l10n\/).*"`
`compressors` ( { ${fileExtension} :: String })
: Map a desired extension (e.g. `gz`) to a compress program.
@ -47,7 +53,11 @@
:::
*/
drv:
{ formats, compressors }:
{
formats,
compressors,
extraFindOperands ? "",
}:
let
validProg =
ext: prog:
@ -61,10 +71,10 @@ let
ext: prog:
assert validProg ext prog;
''
find -L $out -type f -regextype posix-extended -iregex '.*\.(${formatsPipe})' -print0 \
find -L $out -type f -regextype posix-extended -iregex '.*\.(${formatsPipe})' ${extraFindOperands} -print0 \
| xargs -0 -P$NIX_BUILD_CORES -I{} ${prog}
'';
formatsPipe = builtins.concatStringsSep "|" formats;
formatsPipe = lib.concatStringsSep "|" formats;
in
runCommand "${drv.name}-compressed" { } ''
mkdir $out

View File

@ -19,6 +19,10 @@
Defaults to common formats that compress well.
`extraFindOperands` (String)
: See compressDrv for details.
`extraFormats` ([ String ])
: Extra extensions to compress in addition to `formats`.
@ -132,8 +136,10 @@ drv:
# https://github.com/NixOS/nixpkgs/pull/332752#issuecomment-2275110390
zstd = "${lib.getExe zstd} --force --keep --quiet -19 {}";
},
extraFindOperands ? "",
}:
compressDrv drv {
formats = formats ++ extraFormats;
compressors = compressors;
inherit extraFindOperands;
}