Unverified Commit c5ea55f5 authored by Philip Taron's avatar Philip Taron Committed by GitHub
Browse files

Merge pull request #332752 from SuperSandro2000/compressDrv

compressDrv and compressDrvWeb follow up
parents 8d18fe91 0505523e
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
, pango
, pkg-config
, nltk-data
, xorg
}:

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

  nativeBuildInputs = [
    gettext
    xorg.lndir
  ];

  propagatedBuildInputs = with python.pkgs; [
@@ -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}" \
+25 −11
Original line number Diff line number Diff line
@@ -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,16 +71,20 @@ 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" { } ''
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.
    # 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/{} ';')

+22 −8
Original line number Diff line number Diff line
{
  zopfli,
  brotli,
  compressDrv,
  lib,
  zopfli,
  zstd,
}:
/**
  compressDrvWeb compresses a derivation for common web server use.
@@ -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`.
@@ -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 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ stdenv.mkDerivation rec {
    '';
    platforms = platforms.unix;
    license = licenses.asl20;
    mainProgram = "zopfli";
    maintainers = with maintainers; [ bobvanderlinden edef ];
  };
}
+1 −1
Original line number Diff line number Diff line
@@ -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 ];
  };