Skip to content

Commit

Permalink
Merge pull request NixOS#332752 from SuperSandro2000/compressDrv
Browse files Browse the repository at this point in the history
compressDrv and compressDrvWeb follow up
  • Loading branch information
philiptaron authored Aug 19, 2024
2 parents 8d18fe9 + 0505523 commit c5ea55f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 22 deletions.
6 changes: 4 additions & 2 deletions pkgs/applications/office/paperless-ngx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
, pango
, pkg-config
, nltk-data
, xorg
}:

let
Expand Down Expand Up @@ -121,6 +122,7 @@ python.pkgs.buildPythonApplication rec {

nativeBuildInputs = [
gettext
xorg.lndir
];

propagatedBuildInputs = with python.pkgs; [
Expand Down Expand Up @@ -194,9 +196,9 @@ python.pkgs.buildPythonApplication rec {
in ''
runHook preInstall
mkdir -p $out/lib/paperless-ngx
mkdir -p $out/lib/paperless-ngx/static/frontend
cp -r {src,static,LICENSE,gunicorn.conf.py} $out/lib/paperless-ngx
ln -s ${frontend}/lib/paperless-ui/frontend $out/lib/paperless-ngx/static/
lndir -silent ${frontend}/lib/paperless-ui/frontend $out/lib/paperless-ngx/static/frontend
chmod +x $out/lib/paperless-ngx/src/manage.py
makeWrapper $out/lib/paperless-ngx/src/manage.py $out/bin/paperless-ngx \
--prefix PYTHONPATH : "${pythonPath}" \
Expand Down
36 changes: 25 additions & 11 deletions pkgs/build-support/compress-drv/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -47,7 +53,11 @@
:::
*/
drv:
{ formats, compressors }:
{
formats,
compressors,
extraFindOperands ? "",
}:
let
validProg =
ext: prog:
Expand All @@ -61,18 +71,22 @@ 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
runCommand "${drv.name}-compressed"
(
(lib.optionalAttrs (drv ? pname) { inherit (drv) pname; })
// (lib.optionalAttrs (drv ? version) { inherit (drv) version; })
)
''
mkdir $out
# cannot use lndir here, because it also symlinks directories,
# which we do not need; we only need to symlink files.
(cd ${drv}; find -L -type d -exec mkdir -p $out/{} ';')
(cd ${drv}; find -L -type f -exec ln -s ${drv}/{} $out/{} ';')
# cannot use lndir here, because it stop recursing at symlinks that point to directories
(cd ${drv}; find -L -type d -exec mkdir -p $out/{} ';')
(cd ${drv}; find -L -type f -exec ln -s ${drv}/{} $out/{} ';')
${lib.concatStringsSep "\n\n" (lib.mapAttrsToList mkCmd compressors)}
''
${lib.concatStringsSep "\n\n" (lib.mapAttrsToList mkCmd compressors)}
''
30 changes: 22 additions & 8 deletions pkgs/build-support/compress-drv/web.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
zopfli,
brotli,
compressDrv,
lib,
zopfli,
zstd,
}:
/**
compressDrvWeb compresses a derivation for common web server use.
Expand All @@ -17,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`.
Expand Down Expand Up @@ -108,24 +114,32 @@ drv:
{
formats ? [
"css"
"eot"
"htm"
"html"
"js"
"json"
"map"
"otf"
"svg"
"ttf"
"eot"
"txt"
"xml"
"map"
"html"
"json"
"webmanifest"
"xml"
],
extraFormats ? [ ],
compressors ? {
"gz" = "${zopfli}/bin/zopfli --keep {}";
"br" = "${brotli}/bin/brotli --keep --no-copy-stat {}";
br = "${lib.getExe brotli} --keep --no-copy-stat {}";
gz = "${lib.getExe zopfli} --keep {}";
# --force is required to not fail on symlinks
# for details on the compression level see
# 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;
}
1 change: 1 addition & 0 deletions pkgs/tools/compression/zopfli/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ stdenv.mkDerivation rec {
'';
platforms = platforms.unix;
license = licenses.asl20;
mainProgram = "zopfli";
maintainers = with maintainers; [ bobvanderlinden edef ];
};
}
2 changes: 1 addition & 1 deletion pkgs/tools/compression/zstd/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ stdenv.mkDerivation rec {
homepage = "https://facebook.github.io/zstd/";
changelog = "https://github.com/facebook/zstd/blob/v${version}/CHANGELOG";
license = with licenses; [ bsd3 ]; # Or, at your opinion, GPL-2.0-only.

mainProgram = "zstd";
platforms = platforms.all;
maintainers = with maintainers; [ orivej ];
};
Expand Down

0 comments on commit c5ea55f

Please sign in to comment.