mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 06:53:01 +00:00
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:
parent
0ca4bfa700
commit
4cc5dee048
@ -9,6 +9,12 @@
|
|||||||
|
|
||||||
: List of file extensions to compress. Example: `["txt" "svg" "xml"]`.
|
: 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 })
|
`compressors` ( { ${fileExtension} :: String })
|
||||||
|
|
||||||
: Map a desired extension (e.g. `gz`) to a compress program.
|
: Map a desired extension (e.g. `gz`) to a compress program.
|
||||||
@ -47,7 +53,11 @@
|
|||||||
:::
|
:::
|
||||||
*/
|
*/
|
||||||
drv:
|
drv:
|
||||||
{ formats, compressors }:
|
{
|
||||||
|
formats,
|
||||||
|
compressors,
|
||||||
|
extraFindOperands ? "",
|
||||||
|
}:
|
||||||
let
|
let
|
||||||
validProg =
|
validProg =
|
||||||
ext: prog:
|
ext: prog:
|
||||||
@ -61,10 +71,10 @@ let
|
|||||||
ext: prog:
|
ext: prog:
|
||||||
assert validProg 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}
|
| xargs -0 -P$NIX_BUILD_CORES -I{} ${prog}
|
||||||
'';
|
'';
|
||||||
formatsPipe = builtins.concatStringsSep "|" formats;
|
formatsPipe = lib.concatStringsSep "|" formats;
|
||||||
in
|
in
|
||||||
runCommand "${drv.name}-compressed" { } ''
|
runCommand "${drv.name}-compressed" { } ''
|
||||||
mkdir $out
|
mkdir $out
|
||||||
|
@ -19,6 +19,10 @@
|
|||||||
|
|
||||||
Defaults to common formats that compress well.
|
Defaults to common formats that compress well.
|
||||||
|
|
||||||
|
`extraFindOperands` (String)
|
||||||
|
|
||||||
|
: See compressDrv for details.
|
||||||
|
|
||||||
`extraFormats` ([ String ])
|
`extraFormats` ([ String ])
|
||||||
|
|
||||||
: Extra extensions to compress in addition to `formats`.
|
: Extra extensions to compress in addition to `formats`.
|
||||||
@ -132,8 +136,10 @@ drv:
|
|||||||
# https://github.com/NixOS/nixpkgs/pull/332752#issuecomment-2275110390
|
# https://github.com/NixOS/nixpkgs/pull/332752#issuecomment-2275110390
|
||||||
zstd = "${lib.getExe zstd} --force --keep --quiet -19 {}";
|
zstd = "${lib.getExe zstd} --force --keep --quiet -19 {}";
|
||||||
},
|
},
|
||||||
|
extraFindOperands ? "",
|
||||||
}:
|
}:
|
||||||
compressDrv drv {
|
compressDrv drv {
|
||||||
formats = formats ++ extraFormats;
|
formats = formats ++ extraFormats;
|
||||||
compressors = compressors;
|
compressors = compressors;
|
||||||
|
inherit extraFindOperands;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user