about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/compression
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/tools/compression')
-rw-r--r--nixpkgs/pkgs/tools/compression/advancecomp/default.nix36
-rw-r--r--nixpkgs/pkgs/tools/compression/asar/default.nix48
-rw-r--r--nixpkgs/pkgs/tools/compression/asar/package.json62
-rw-r--r--nixpkgs/pkgs/tools/compression/brotli/default.nix78
-rw-r--r--nixpkgs/pkgs/tools/compression/bsc/default.nix34
-rw-r--r--nixpkgs/pkgs/tools/compression/bsdiff/CVE-2020-14315.patch384
-rw-r--r--nixpkgs/pkgs/tools/compression/bsdiff/default.nix57
-rw-r--r--nixpkgs/pkgs/tools/compression/bsdiff/include-systypes.patch12
-rw-r--r--nixpkgs/pkgs/tools/compression/bzip2/1_1.nix47
-rw-r--r--nixpkgs/pkgs/tools/compression/bzip2/default.nix75
-rw-r--r--nixpkgs/pkgs/tools/compression/bzip3/default.nix50
-rw-r--r--nixpkgs/pkgs/tools/compression/crabz/default.nix30
-rw-r--r--nixpkgs/pkgs/tools/compression/dejsonlz4/default.nix31
-rw-r--r--nixpkgs/pkgs/tools/compression/dtrx/default.nix56
-rw-r--r--nixpkgs/pkgs/tools/compression/efficient-compression-tool/default.nix45
-rw-r--r--nixpkgs/pkgs/tools/compression/efficient-compression-tool/use-nixpkgs-libpng.patch108
-rw-r--r--nixpkgs/pkgs/tools/compression/flips/default.nix32
-rw-r--r--nixpkgs/pkgs/tools/compression/flips/use-system-libdivsufsort.patch15
-rw-r--r--nixpkgs/pkgs/tools/compression/gzip/default.nix72
-rw-r--r--nixpkgs/pkgs/tools/compression/gzrt/default.nix27
-rw-r--r--nixpkgs/pkgs/tools/compression/hacpack/default.nix34
-rw-r--r--nixpkgs/pkgs/tools/compression/hactool/default.nix36
-rw-r--r--nixpkgs/pkgs/tools/compression/hactool/musl-compat.patch13
-rw-r--r--nixpkgs/pkgs/tools/compression/heatshrink/default.nix49
-rw-r--r--nixpkgs/pkgs/tools/compression/imagelol/default.nix59
-rw-r--r--nixpkgs/pkgs/tools/compression/keka/default.nix38
-rw-r--r--nixpkgs/pkgs/tools/compression/kzipmix/default.nix27
-rw-r--r--nixpkgs/pkgs/tools/compression/lbzip2/default.nix40
-rw-r--r--nixpkgs/pkgs/tools/compression/lhasa/default.nix25
-rw-r--r--nixpkgs/pkgs/tools/compression/lrzip/default.nix41
-rw-r--r--nixpkgs/pkgs/tools/compression/lz4/default.nix70
-rw-r--r--nixpkgs/pkgs/tools/compression/lzbench/default.nix28
-rw-r--r--nixpkgs/pkgs/tools/compression/lzfse/default.nix29
-rw-r--r--nixpkgs/pkgs/tools/compression/lzham/default.nix27
-rw-r--r--nixpkgs/pkgs/tools/compression/lzip/default.nix42
-rw-r--r--nixpkgs/pkgs/tools/compression/lzip/lzip-setup-hook.sh5
-rw-r--r--nixpkgs/pkgs/tools/compression/lzip/mingw-install-exe-file.patch13
-rw-r--r--nixpkgs/pkgs/tools/compression/lziprecover/default.nix32
-rw-r--r--nixpkgs/pkgs/tools/compression/lzop/default.nix22
-rw-r--r--nixpkgs/pkgs/tools/compression/mozlz4a/default.nix39
-rw-r--r--nixpkgs/pkgs/tools/compression/ncompress/default.nix27
-rw-r--r--nixpkgs/pkgs/tools/compression/nx2elf/default.nix34
-rw-r--r--nixpkgs/pkgs/tools/compression/offzip/default.nix33
-rw-r--r--nixpkgs/pkgs/tools/compression/orz/default.nix40
-rw-r--r--nixpkgs/pkgs/tools/compression/ouch/default.nix54
-rw-r--r--nixpkgs/pkgs/tools/compression/pbzip2/default.nix30
-rw-r--r--nixpkgs/pkgs/tools/compression/pbzx/default.nix27
-rw-r--r--nixpkgs/pkgs/tools/compression/pigz/default.nix41
-rw-r--r--nixpkgs/pkgs/tools/compression/pixz/default.nix52
-rw-r--r--nixpkgs/pkgs/tools/compression/pxz/default.nix56
-rw-r--r--nixpkgs/pkgs/tools/compression/pxz/flush-stdout-help-version.patch32
-rw-r--r--nixpkgs/pkgs/tools/compression/rzip/default.nix31
-rw-r--r--nixpkgs/pkgs/tools/compression/unzrip/default.nix36
-rw-r--r--nixpkgs/pkgs/tools/compression/upx/default.nix35
-rw-r--r--nixpkgs/pkgs/tools/compression/xar/0001-Add-useless-descriptions-to-AC_DEFINE.patch95
-rw-r--r--nixpkgs/pkgs/tools/compression/xar/0002-Use-pkg-config-for-libxml2.patch89
-rw-r--r--nixpkgs/pkgs/tools/compression/xar/default.nix49
-rw-r--r--nixpkgs/pkgs/tools/compression/xdelta/default.nix62
-rw-r--r--nixpkgs/pkgs/tools/compression/xdelta/unstable.nix66
-rw-r--r--nixpkgs/pkgs/tools/compression/xz/default.nix81
-rw-r--r--nixpkgs/pkgs/tools/compression/zdelta/default.nix24
-rw-r--r--nixpkgs/pkgs/tools/compression/zfp/default.nix57
-rw-r--r--nixpkgs/pkgs/tools/compression/zopfli/default.nix39
-rw-r--r--nixpkgs/pkgs/tools/compression/zstd/default.nix129
-rw-r--r--nixpkgs/pkgs/tools/compression/zstd/playtests-darwin.patch40
-rw-r--r--nixpkgs/pkgs/tools/compression/zsync/default.nix21
66 files changed, 3248 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/tools/compression/advancecomp/default.nix b/nixpkgs/pkgs/tools/compression/advancecomp/default.nix
new file mode 100644
index 000000000000..b57e3f6806f3
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/advancecomp/default.nix
@@ -0,0 +1,36 @@
+{ lib, stdenv
+, fetchFromGitHub
+, autoreconfHook
+, zlib
+}:
+
+stdenv.mkDerivation rec {
+  pname = "advancecomp";
+  version = "2.6";
+
+  src = fetchFromGitHub {
+    owner = "amadvance";
+    repo = "advancecomp";
+    rev = "v${version}";
+    hash = "sha256-MwXdXT/ZEvTcYV4DjhCUFflrPKBFu0fk5PmaWt4MMOU=";
+  };
+
+  nativeBuildInputs = [ autoreconfHook ];
+  buildInputs = [ zlib ];
+
+  # autover.sh relies on 'git describe', which obviously doesn't work as we're not cloning
+  # the full git repo. so we have to put the version number in `.version`, otherwise
+  # the binaries get built reporting "none" as their version number.
+  postPatch = ''
+    echo "${version}" >.version
+  '';
+
+  meta = with lib; {
+    description = "A set of tools to optimize deflate-compressed files";
+    license = licenses.gpl3 ;
+    maintainers = [ maintainers.raskin ];
+    platforms = platforms.linux ++ platforms.darwin;
+    homepage = "https://github.com/amadvance/advancecomp";
+
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/asar/default.nix b/nixpkgs/pkgs/tools/compression/asar/default.nix
new file mode 100644
index 000000000000..3d6c017674a8
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/asar/default.nix
@@ -0,0 +1,48 @@
+{ lib
+, mkYarnPackage
+, fetchFromGitHub
+, fetchYarnDeps
+}:
+
+mkYarnPackage rec {
+  pname = "asar";
+  version = "3.2.4";
+
+  src = fetchFromGitHub {
+    owner = "electron";
+    repo = "asar";
+    rev = "v${version}";
+    hash = "sha256-12FP8VRDo1PQ+tiN4zhzkcfAx9zFs/0MU03t/vFo074=";
+  };
+
+  packageJSON = ./package.json;
+
+  offlineCache = fetchYarnDeps {
+    yarnLock = "${src}/yarn.lock";
+    hash = "sha256-/fV3hd98pl46+fgmiMH9sDQrrZgdLY1oF9c3TaIxRSg=";
+  };
+
+  doDist = false;
+
+  installPhase = ''
+    runHook preInstall
+
+    mkdir -p "$out/lib/node_modules"
+    mv deps/@electron "$out/lib/node_modules"
+    rm "$out/lib/node_modules/@electron/asar/node_modules"
+    mv node_modules "$out/lib/node_modules/@electron/asar"
+
+    mkdir "$out/bin"
+    ln -s "$out/lib/node_modules/@electron/asar/bin/asar.js" "$out/bin/asar"
+
+    runHook postInstall
+  '';
+
+  meta = {
+    description = "Simple extensive tar-like archive format with indexing";
+    homepage = "https://github.com/electron/asar";
+    license = lib.licenses.mit;
+    mainProgram = "asar";
+    maintainers = with lib.maintainers; [ xvapx ];
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/asar/package.json b/nixpkgs/pkgs/tools/compression/asar/package.json
new file mode 100644
index 000000000000..51ed0e24ffeb
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/asar/package.json
@@ -0,0 +1,62 @@
+{
+  "name": "@electron/asar",
+  "description": "Creating Electron app packages",
+  "version": "0.0.0-development",
+  "main": "./lib/asar.js",
+  "types": "./lib/index.d.ts",
+  "bin": {
+    "asar": "./bin/asar.js"
+  },
+  "files": [
+    "bin",
+    "lib",
+    "lib/index.d.ts"
+  ],
+  "engines": {
+    "node": ">=10.12.0"
+  },
+  "license": "MIT",
+  "homepage": "https://github.com/electron/asar",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/electron/asar.git"
+  },
+  "bugs": {
+    "url": "https://github.com/electron/asar/issues"
+  },
+  "scripts": {
+    "mocha": "xvfb-maybe electron-mocha --reporter spec && mocha --reporter spec",
+    "test": "npm run lint && npm run mocha",
+    "lint": "tsd && standard",
+    "standard": "standard",
+    "tsd": "tsd"
+  },
+  "standard": {
+    "env": {
+      "mocha": true
+    },
+    "globals": [
+      "BigInt"
+    ]
+  },
+  "tsd": {
+    "directory": "test"
+  },
+  "dependencies": {
+    "chromium-pickle-js": "^0.2.0",
+    "commander": "^5.0.0",
+    "glob": "^7.1.6",
+    "minimatch": "^3.0.4"
+  },
+  "devDependencies": {
+    "@continuous-auth/semantic-release-npm": "^3.0.0",
+    "electron": "^22.0.0",
+    "electron-mocha": "^11.0.2",
+    "lodash": "^4.17.15",
+    "mocha": "^10.1.0",
+    "rimraf": "^3.0.2",
+    "standard": "^14.3.3",
+    "tsd": "^0.25.0",
+    "xvfb-maybe": "^0.2.1"
+  }
+}
diff --git a/nixpkgs/pkgs/tools/compression/brotli/default.nix b/nixpkgs/pkgs/tools/compression/brotli/default.nix
new file mode 100644
index 000000000000..60429f435ec6
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/brotli/default.nix
@@ -0,0 +1,78 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, fetchpatch
+, cmake
+, staticOnly ? stdenv.hostPlatform.isStatic
+, testers
+}:
+
+# ?TODO: there's also python lib in there
+
+stdenv.mkDerivation (finalAttrs: {
+  pname = "brotli";
+  version = "1.1.0";
+
+  src = fetchFromGitHub {
+    owner = "google";
+    repo = "brotli";
+    rev = "v${finalAttrs.version}";
+    hash = "sha256-MvceRcle2dSkkucC2PlsCizsIf8iv95d8Xjqew266wc=";
+  };
+
+  patches = [
+    # revert runpath change, breaks curl on darwin:
+    #   https://github.com/NixOS/nixpkgs/pull/254532#issuecomment-1722337476
+    (fetchpatch {
+      name = "revert-runpath.patch";
+      url = "https://github.com/google/brotli/commit/f842c1bcf9264431cd3b15429a72b7dafbe80509.patch";
+      hash = "sha256-W3LY3EjoHP74YsKOOcYQrzo+f0HbooOvEbnOibtN6TM=";
+      revert = true;
+    })
+  ];
+
+  nativeBuildInputs = [ cmake ];
+
+  cmakeFlags = lib.optional staticOnly "-DBUILD_SHARED_LIBS=OFF";
+
+  outputs = [ "out" "dev" "lib" ];
+
+  doCheck = true;
+
+  checkTarget = "test";
+
+  # Don't bother with "man" output for now,
+  # it currently only makes the manpages hard to use.
+  postInstall = ''
+    mkdir -p $out/share/man/man{1,3}
+    cp ../docs/*.1 $out/share/man/man1/
+    cp ../docs/*.3 $out/share/man/man3/
+  '';
+
+  passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
+
+  meta = with lib; {
+    homepage = "https://github.com/google/brotli";
+    description = "A generic-purpose lossless compression algorithm and tool";
+    longDescription =
+      ''  Brotli is a generic-purpose lossless compression algorithm that
+          compresses data using a combination of a modern variant of the LZ77
+          algorithm, Huffman coding and 2nd order context modeling, with a
+          compression ratio comparable to the best currently available
+          general-purpose compression methods. It is similar in speed with
+          deflate but offers more dense compression.
+
+          The specification of the Brotli Compressed Data Format is defined
+          in the following internet draft:
+          http://www.ietf.org/id/draft-alakuijala-brotli
+      '';
+    license = licenses.mit;
+    maintainers = with maintainers; [ freezeboy ];
+    pkgConfigModules = [
+      "libbrotlidec"
+      "libbrotlienc"
+    ];
+    platforms = platforms.all;
+    mainProgram = "brotli";
+  };
+})
diff --git a/nixpkgs/pkgs/tools/compression/bsc/default.nix b/nixpkgs/pkgs/tools/compression/bsc/default.nix
new file mode 100644
index 000000000000..7d2af1c4898f
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/bsc/default.nix
@@ -0,0 +1,34 @@
+{ lib, stdenv, fetchFromGitHub, openmp }:
+
+stdenv.mkDerivation rec {
+  pname = "bsc";
+  version = "3.1.0";
+
+  src = fetchFromGitHub {
+    owner = "IlyaGrebnov";
+    repo = "libbsc";
+    rev = version;
+    sha256 = "0c0jmirh9y23kyi1jnrm13sa3xsjn54jazfr84ag45pai279fciz";
+  };
+
+  enableParallelBuilding = true;
+
+  buildInputs = lib.optional stdenv.isDarwin openmp;
+
+  postPatch = ''
+    substituteInPlace makefile \
+        --replace 'g++' '$(CXX)'
+  '';
+
+  makeFlags = [ "PREFIX=$(out)" ];
+
+  meta = with lib; {
+    description = "High performance block-sorting data compression library";
+    homepage = "http://libbsc.com/";
+    maintainers = with maintainers; [ ];
+    # Later commits changed the licence to Apache2 (no release yet, though)
+    license = with licenses; [ lgpl3Plus ];
+    platforms = platforms.unix;
+    mainProgram = "bsc";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/bsdiff/CVE-2020-14315.patch b/nixpkgs/pkgs/tools/compression/bsdiff/CVE-2020-14315.patch
new file mode 100644
index 000000000000..bb7ff41284eb
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/bsdiff/CVE-2020-14315.patch
@@ -0,0 +1,384 @@
+Description: patch for CVE-2020-14315
+ A memory corruption vulnerability is present in bspatch as shipped in
+ Colin Percival’s bsdiff tools version 4.3. Insufficient checks when
+ handling external inputs allows an attacker to bypass the sanity checks
+ in place and write out of a dynamically allocated buffer boundaries.
+Source: https://svnweb.freebsd.org/base/head/usr.bin/bsdiff/bspatch/bspatch.c?revision=352742&view=co
+Author: tony mancill <tmancill@debian.org>
+Comment: The patch was created by comparing the Debian sources to the
+ "Confirmed Patched Version" [1] documented in the
+ X41 D-SEC GmbH Security Advisory: X41-2020-006 [2].
+ References to FreeBSD capsicum have been dropped.  Definitions for
+ TYPE_MINIMUM and TYPE_MAXIMUM have been borrowed from the Debian
+ coreutils package sources but originate in gnulib [3] and are used to
+ define OFF_MIN and OFF_MAX (limits of off_t). Whitespace changes from
+ the confirmed patched version are also included and keep the difference
+ between the Debian sources and the confirmed patched version minimal.
+ .
+ [1] https://svnweb.freebsd.org/base/head/usr.bin/bsdiff/bspatch/bspatch.c?revision=352742&view=co
+ [2] https://www.openwall.com/lists/oss-security/2020/07/09/2
+ [3] https://www.gnu.org/software/gnulib/
+Last-Update: 2021-04-03
+Forwarded: not-needed
+Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=964796
+
+--- a/bspatch.c
++++ b/bspatch.c
+@@ -1,4 +1,6 @@
+ /*-
++ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
++ *
+  * Copyright 2003-2005 Colin Percival
+  * All rights reserved
+  *
+@@ -24,56 +26,148 @@
+  * POSSIBILITY OF SUCH DAMAGE.
+  */
+ 
++#include <sys/cdefs.h>
+ #if 0
+-__FBSDID("$FreeBSD: src/usr.bin/bsdiff/bspatch/bspatch.c,v 1.1 2005/08/06 01:59:06 cperciva Exp $");
++__FBSDID("$FreeBSD$");
+ #endif
+ 
+ #include <bzlib.h>
+-#include <stdlib.h>
++#include <err.h>
++#include <fcntl.h>
++#include <libgen.h>
++#include <limits.h>
++#include <stdint.h>
+ #include <stdio.h>
++#include <stdlib.h>
+ #include <string.h>
+-#include <err.h>
+ #include <unistd.h>
+-#include <fcntl.h>
++
++#ifndef O_BINARY
++#define O_BINARY 0
++#endif
++#define HEADER_SIZE 32
++
++/* TYPE_MINIMUM and TYPE_MAXIMUM taken from coreutils */
++#ifndef TYPE_MINIMUM
++#define TYPE_MINIMUM(t) \
++  ((t) ((t) 0 < (t) -1 ? (t) 0 : ~ TYPE_MAXIMUM (t)))
++#endif
++#ifndef TYPE_MAXIMUM
++#define TYPE_MAXIMUM(t) \
++  ((t) ((t) 0 < (t) -1 \
++        ? (t) -1 \
++        : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
++#endif
++
++#ifndef OFF_MAX
++#define OFF_MAX TYPE_MAXIMUM(off_t)
++#endif
++
++#ifndef OFF_MIN
++#define OFF_MIN TYPE_MINIMUM(off_t)
++#endif
++
++static char *newfile;
++static int dirfd = -1;
++
++static void
++exit_cleanup(void)
++{
++
++	if (dirfd != -1 && newfile != NULL)
++		if (unlinkat(dirfd, newfile, 0))
++			warn("unlinkat");
++}
++
++static inline off_t
++add_off_t(off_t a, off_t b)
++{
++	off_t result;
++
++#if __GNUC__ >= 5
++	if (__builtin_add_overflow(a, b, &result))
++		errx(1, "Corrupt patch");
++#else
++	if ((b > 0 && a > OFF_MAX - b) || (b < 0 && a < OFF_MIN - b))
++		errx(1, "Corrupt patch");
++	result = a + b;
++#endif
++	return result;
++}
+ 
+ static off_t offtin(u_char *buf)
+ {
+ 	off_t y;
+ 
+-	y=buf[7]&0x7F;
+-	y=y*256;y+=buf[6];
+-	y=y*256;y+=buf[5];
+-	y=y*256;y+=buf[4];
+-	y=y*256;y+=buf[3];
+-	y=y*256;y+=buf[2];
+-	y=y*256;y+=buf[1];
+-	y=y*256;y+=buf[0];
++	y = buf[7] & 0x7F;
++	y = y * 256; y += buf[6];
++	y = y * 256; y += buf[5];
++	y = y * 256; y += buf[4];
++	y = y * 256; y += buf[3];
++	y = y * 256; y += buf[2];
++	y = y * 256; y += buf[1];
++	y = y * 256; y += buf[0];
+ 
+-	if(buf[7]&0x80) y=-y;
++	if (buf[7] & 0x80)
++		y = -y;
+ 
+-	return y;
++	return (y);
+ }
+ 
+-int main(int argc,char * argv[])
++static void
++usage(void)
+ {
+-	FILE * f, * cpf, * dpf, * epf;
+-	BZFILE * cpfbz2, * dpfbz2, * epfbz2;
++
++	fprintf(stderr, "usage: bspatch oldfile newfile patchfile\n");
++	exit(1);
++}
++
++int main(int argc, char *argv[])
++{
++	FILE *f, *cpf, *dpf, *epf;
++	BZFILE *cpfbz2, *dpfbz2, *epfbz2;
++	char *directory, *namebuf;
+ 	int cbz2err, dbz2err, ebz2err;
+-	int fd;
+-	ssize_t oldsize,newsize;
+-	ssize_t bzctrllen,bzdatalen;
+-	u_char header[32],buf[8];
++	int newfd, oldfd;
++	off_t oldsize, newsize;
++	off_t bzctrllen, bzdatalen;
++	u_char header[HEADER_SIZE], buf[8];
+ 	u_char *old, *new;
+-	off_t oldpos,newpos;
++	off_t oldpos, newpos;
+ 	off_t ctrl[3];
+-	off_t lenread;
+-	off_t i;
++	off_t i, lenread, offset;
+ 
+-	if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]);
++	if (argc != 4)
++		usage();
+ 
+ 	/* Open patch file */
+-	if ((f = fopen(argv[3], "r")) == NULL)
++	if ((f = fopen(argv[3], "rb")) == NULL)
++		err(1, "fopen(%s)", argv[3]);
++	/* Open patch file for control block */
++	if ((cpf = fopen(argv[3], "rb")) == NULL)
++		err(1, "fopen(%s)", argv[3]);
++	/* open patch file for diff block */
++	if ((dpf = fopen(argv[3], "rb")) == NULL)
+ 		err(1, "fopen(%s)", argv[3]);
++	/* open patch file for extra block */
++	if ((epf = fopen(argv[3], "rb")) == NULL)
++		err(1, "fopen(%s)", argv[3]);
++	/* open oldfile */
++	if ((oldfd = open(argv[1], O_RDONLY | O_BINARY, 0)) < 0)
++		err(1, "open(%s)", argv[1]);
++	/* open directory where we'll write newfile */
++	if ((namebuf = strdup(argv[2])) == NULL ||
++	    (directory = dirname(namebuf)) == NULL ||
++	    (dirfd = open(directory, O_DIRECTORY)) < 0)
++		err(1, "open %s", argv[2]);
++	free(namebuf);
++	if ((newfile = basename(argv[2])) == NULL)
++		err(1, "basename");
++	/* open newfile */
++	if ((newfd = openat(dirfd, newfile,
++	    O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0666)) < 0)
++		err(1, "open(%s)", argv[2]);
++	atexit(exit_cleanup);
+ 
+ 	/*
+ 	File format:
+@@ -90,104 +185,104 @@
+ 	*/
+ 
+ 	/* Read header */
+-	if (fread(header, 1, 32, f) < 32) {
++	if (fread(header, 1, HEADER_SIZE, f) < HEADER_SIZE) {
+ 		if (feof(f))
+-			errx(1, "Corrupt patch\n");
++			errx(1, "Corrupt patch");
+ 		err(1, "fread(%s)", argv[3]);
+ 	}
+ 
+ 	/* Check for appropriate magic */
+ 	if (memcmp(header, "BSDIFF40", 8) != 0)
+-		errx(1, "Corrupt patch\n");
++		errx(1, "Corrupt patch");
+ 
+ 	/* Read lengths from header */
+-	bzctrllen=offtin(header+8);
+-	bzdatalen=offtin(header+16);
+-	newsize=offtin(header+24);
+-	if((bzctrllen<0) || (bzdatalen<0) || (newsize<0))
+-		errx(1,"Corrupt patch\n");
++	bzctrllen = offtin(header + 8);
++	bzdatalen = offtin(header + 16);
++	newsize = offtin(header + 24);
++	if (bzctrllen < 0 || bzctrllen > OFF_MAX - HEADER_SIZE ||
++	    bzdatalen < 0 || bzctrllen + HEADER_SIZE > OFF_MAX - bzdatalen ||
++	    newsize < 0 || newsize > SSIZE_MAX)
++		errx(1, "Corrupt patch");
+ 
+ 	/* Close patch file and re-open it via libbzip2 at the right places */
+ 	if (fclose(f))
+ 		err(1, "fclose(%s)", argv[3]);
+-	if ((cpf = fopen(argv[3], "r")) == NULL)
+-		err(1, "fopen(%s)", argv[3]);
+-	if (fseeko(cpf, 32, SEEK_SET))
+-		err(1, "fseeko(%s, %lld)", argv[3],
+-		    (long long)32);
++	offset = HEADER_SIZE;
++	if (fseeko(cpf, offset, SEEK_SET))
++		err(1, "fseeko(%s, %jd)", argv[3], (intmax_t)offset);
+ 	if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL)
+ 		errx(1, "BZ2_bzReadOpen, bz2err = %d", cbz2err);
+-	if ((dpf = fopen(argv[3], "r")) == NULL)
+-		err(1, "fopen(%s)", argv[3]);
+-	if (fseeko(dpf, 32 + bzctrllen, SEEK_SET))
+-		err(1, "fseeko(%s, %lld)", argv[3],
+-		    (long long)(32 + bzctrllen));
++	offset = add_off_t(offset, bzctrllen);
++	if (fseeko(dpf, offset, SEEK_SET))
++		err(1, "fseeko(%s, %jd)", argv[3], (intmax_t)offset);
+ 	if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL)
+ 		errx(1, "BZ2_bzReadOpen, bz2err = %d", dbz2err);
+-	if ((epf = fopen(argv[3], "r")) == NULL)
+-		err(1, "fopen(%s)", argv[3]);
+-	if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET))
+-		err(1, "fseeko(%s, %lld)", argv[3],
+-		    (long long)(32 + bzctrllen + bzdatalen));
++	offset = add_off_t(offset, bzdatalen);
++	if (fseeko(epf, offset, SEEK_SET))
++		err(1, "fseeko(%s, %jd)", argv[3], (intmax_t)offset);
+ 	if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL)
+ 		errx(1, "BZ2_bzReadOpen, bz2err = %d", ebz2err);
+ 
+-	if(((fd=open(argv[1],O_RDONLY,0))<0) ||
+-		((oldsize=lseek(fd,0,SEEK_END))==-1) ||
+-		((old=malloc(oldsize+1))==NULL) ||
+-		(lseek(fd,0,SEEK_SET)!=0) ||
+-		(read(fd,old,oldsize)!=oldsize) ||
+-		(close(fd)==-1)) err(1,"%s",argv[1]);
+-	if((new=malloc(newsize+1))==NULL) err(1,NULL);
+-
+-	oldpos=0;newpos=0;
+-	while(newpos<newsize) {
++	if ((oldsize = lseek(oldfd, 0, SEEK_END)) == -1 ||
++	    oldsize > SSIZE_MAX ||
++	    (old = malloc(oldsize)) == NULL ||
++	    lseek(oldfd, 0, SEEK_SET) != 0 ||
++	    read(oldfd, old, oldsize) != oldsize ||
++	    close(oldfd) == -1)
++		err(1, "%s", argv[1]);
++	if ((new = malloc(newsize)) == NULL)
++		err(1, NULL);
++
++	oldpos = 0;
++	newpos = 0;
++	while (newpos < newsize) {
+ 		/* Read control data */
+-		for(i=0;i<=2;i++) {
++		for (i = 0; i <= 2; i++) {
+ 			lenread = BZ2_bzRead(&cbz2err, cpfbz2, buf, 8);
+ 			if ((lenread < 8) || ((cbz2err != BZ_OK) &&
+ 			    (cbz2err != BZ_STREAM_END)))
+-				errx(1, "Corrupt patch\n");
+-			ctrl[i]=offtin(buf);
+-		};
++				errx(1, "Corrupt patch");
++			ctrl[i] = offtin(buf);
++		}
+ 
+ 		/* Sanity-check */
+-		if ((ctrl[0] < 0) || (ctrl[1] < 0))
+-			errx(1,"Corrupt patch\n");
++		if (ctrl[0] < 0 || ctrl[0] > INT_MAX ||
++		    ctrl[1] < 0 || ctrl[1] > INT_MAX)
++			errx(1, "Corrupt patch");
+ 
+ 		/* Sanity-check */
+-		if(newpos+ctrl[0]>newsize)
+-			errx(1,"Corrupt patch\n");
++		if (add_off_t(newpos, ctrl[0]) > newsize)
++			errx(1, "Corrupt patch");
+ 
+ 		/* Read diff string */
+ 		lenread = BZ2_bzRead(&dbz2err, dpfbz2, new + newpos, ctrl[0]);
+ 		if ((lenread < ctrl[0]) ||
+ 		    ((dbz2err != BZ_OK) && (dbz2err != BZ_STREAM_END)))
+-			errx(1, "Corrupt patch\n");
++			errx(1, "Corrupt patch");
+ 
+ 		/* Add old data to diff string */
+-		for(i=0;i<ctrl[0];i++)
+-			if((oldpos+i>=0) && (oldpos+i<oldsize))
+-				new[newpos+i]+=old[oldpos+i];
++		for (i = 0; i < ctrl[0]; i++)
++			if (add_off_t(oldpos, i) < oldsize)
++				new[newpos + i] += old[oldpos + i];
+ 
+ 		/* Adjust pointers */
+-		newpos+=ctrl[0];
+-		oldpos+=ctrl[0];
++		newpos = add_off_t(newpos, ctrl[0]);
++		oldpos = add_off_t(oldpos, ctrl[0]);
+ 
+ 		/* Sanity-check */
+-		if(newpos+ctrl[1]>newsize)
+-			errx(1,"Corrupt patch\n");
++		if (add_off_t(newpos, ctrl[1]) > newsize)
++			errx(1, "Corrupt patch");
+ 
+ 		/* Read extra string */
+ 		lenread = BZ2_bzRead(&ebz2err, epfbz2, new + newpos, ctrl[1]);
+ 		if ((lenread < ctrl[1]) ||
+ 		    ((ebz2err != BZ_OK) && (ebz2err != BZ_STREAM_END)))
+-			errx(1, "Corrupt patch\n");
++			errx(1, "Corrupt patch");
+ 
+ 		/* Adjust pointers */
+-		newpos+=ctrl[1];
+-		oldpos+=ctrl[2];
+-	};
++		newpos = add_off_t(newpos, ctrl[1]);
++		oldpos = add_off_t(oldpos, ctrl[2]);
++	}
+ 
+ 	/* Clean up the bzip2 reads */
+ 	BZ2_bzReadClose(&cbz2err, cpfbz2);
+@@ -197,12 +292,13 @@
+ 		err(1, "fclose(%s)", argv[3]);
+ 
+ 	/* Write the new file */
+-	if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0666))<0) ||
+-		(write(fd,new,newsize)!=newsize) || (close(fd)==-1))
+-		err(1,"%s",argv[2]);
++	if (write(newfd, new, newsize) != newsize || close(newfd) == -1)
++		err(1, "%s", argv[2]);
++	/* Disable atexit cleanup */
++	newfile = NULL;
+ 
+ 	free(new);
+ 	free(old);
+ 
+-	return 0;
++	return (0);
+ }
diff --git a/nixpkgs/pkgs/tools/compression/bsdiff/default.nix b/nixpkgs/pkgs/tools/compression/bsdiff/default.nix
new file mode 100644
index 000000000000..6db5d9924677
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/bsdiff/default.nix
@@ -0,0 +1,57 @@
+{ lib, stdenv, fetchurl, fetchpatch, bzip2 }:
+
+stdenv.mkDerivation rec {
+  pname = "bsdiff";
+  version = "4.3";
+
+  src = fetchurl {
+    url = "https://www.daemonology.net/bsdiff/${pname}-${version}.tar.gz";
+    sha256 = "0j2zm3z271x5aw63mwhr3vymzn45p2vvrlrpm9cz2nywna41b0hq";
+  };
+
+  buildInputs = [ bzip2 ];
+  patches = [
+    (fetchpatch {
+      url = "https://sources.debian.org/data/main/b/bsdiff/4.3-22/debian/patches/20-CVE-2014-9862.patch";
+      sha256 = "sha256-3UuUfNvShQ8fLqxCKUTb/n4BmjL4+Nl7aEqCxYrrERQ=";
+    })
+    ./CVE-2020-14315.patch
+    ./include-systypes.patch
+  ] ++ lib.optionals stdenv.hostPlatform.isLinux [
+    (fetchpatch {
+      url = "https://sources.debian.org/data/main/b/bsdiff/4.3-22/debian/patches/30-bug-632585-mmap-src-file-instead-of-malloc-read-it.patch";
+      sha256 = "sha256-esbhz2/efUiuQDuF7LGfSeEn3/f1WbqCxQpTs2A0ulI=";
+    })
+    (fetchpatch {
+      url = "https://sources.debian.org/data/main/b/bsdiff/4.3-22/debian/patches/31-bug-632585-mmap-dst-file-instead-of-malloc-read-it.patch";
+      sha256 = "sha256-Of4aOcI0rsgdRzPqyw2VRn2p9wQuo3hdlgDTBdXGzoc=";
+    })
+    (fetchpatch {
+      url = "https://sources.debian.org/data/main/b/bsdiff/4.3-22/debian/patches/32-bug-632585-use-int32_t-instead-off_t-for-file-size.patch";
+      sha256 = "sha256-SooFnFK4uKNXvXQb/LEcH8GocnRtkryExI4b3BZTsAY=";
+    })
+  ];
+
+  buildPhase = ''
+    $CC -O3 -lbz2 bspatch.c -o bspatch
+    $CC -O3 -lbz2 bsdiff.c  -o bsdiff
+  '';
+
+  installPhase = ''
+    mkdir -p $out/bin
+    mkdir -p $out/share/man/man1
+
+    cp bsdiff    $out/bin
+    cp bspatch   $out/bin
+    cp bsdiff.1  $out/share/man/man1
+    cp bspatch.1 $out/share/man/man1
+  '';
+
+  meta = with lib; {
+    description = "An efficient binary diff/patch tool";
+    homepage = "https://www.daemonology.net/bsdiff/";
+    license = licenses.bsd2;
+    platforms = platforms.unix;
+    maintainers = [ maintainers.thoughtpolice ];
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/bsdiff/include-systypes.patch b/nixpkgs/pkgs/tools/compression/bsdiff/include-systypes.patch
new file mode 100644
index 000000000000..d070a8bb0f85
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/bsdiff/include-systypes.patch
@@ -0,0 +1,12 @@
+diff --git a/bspatch.c b/bspatch.c
+index 643c60b..543379c 100644
+--- a/bspatch.c
++++ b/bspatch.c
+@@ -28,6 +28,7 @@
+ __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bspatch/bspatch.c,v 1.1 2005/08/06 01:59:06 cperciva Exp $");
+ #endif
+ 
++#include <sys/types.h>
+ #include <bzlib.h>
+ #include <stdlib.h>
+ #include <stdio.h>
diff --git a/nixpkgs/pkgs/tools/compression/bzip2/1_1.nix b/nixpkgs/pkgs/tools/compression/bzip2/1_1.nix
new file mode 100644
index 000000000000..e9d6f7c44dab
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/bzip2/1_1.nix
@@ -0,0 +1,47 @@
+{ lib, stdenv
+, fetchFromGitLab
+, meson
+, python3
+, ninja
+, testers
+}:
+
+stdenv.mkDerivation (finalAttrs: {
+  pname = "bzip2-unstable";
+  version = "2020-08-11";
+
+  src = fetchFromGitLab {
+    owner = "federicomenaquintero";
+    repo = "bzip2";
+    rev = "15255b553e7c095fb7a26d4dc5819a11352ebba1";
+    sha256 = "sha256-BAyz35D62LWi47B/gNcCSKpdaECHBGSpt21vtnk3fKs=";
+  };
+
+  postPatch = ''
+    patchShebangs install_links.py
+  '';
+
+  nativeBuildInputs = [
+    meson
+    python3
+    ninja
+  ];
+
+  outputs = [ "bin" "dev" "out" "man" ];
+
+  mesonFlags = [
+    "-Ddocs=disabled"
+  ];
+
+  strictDeps = true;
+
+  passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
+
+  meta = with lib; {
+    description = "High-quality data compression program";
+    license = licenses.bsdOriginal;
+    pkgConfigModules = [ "bz2" ];
+    platforms = platforms.all;
+    maintainers = [];
+  };
+})
diff --git a/nixpkgs/pkgs/tools/compression/bzip2/default.nix b/nixpkgs/pkgs/tools/compression/bzip2/default.nix
new file mode 100644
index 000000000000..bfab2dbb9467
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/bzip2/default.nix
@@ -0,0 +1,75 @@
+{ lib, stdenv, fetchurl
+, enableStatic ? with stdenv.hostPlatform; isStatic || isCygwin
+, enableShared ? true
+, autoreconfHook
+, testers
+}:
+
+# Note: this package is used for bootstrapping fetchurl, and thus
+# cannot use fetchpatch! All mutable patches (generated by GitHub or
+# cgit) that are needed here should be included directly in Nixpkgs as
+# files.
+
+stdenv.mkDerivation (finalAttrs: let
+  inherit (finalAttrs) version;
+in {
+  pname = "bzip2";
+  version = "1.0.8";
+
+  src = fetchurl {
+    url = "https://sourceware.org/pub/bzip2/bzip2-${version}.tar.gz";
+    sha256 = "sha256-q1oDF27hBtPw+pDjgdpHjdrkBZGBU8yiSOaCzQxKImk=";
+  };
+
+  patchFlags = ["-p0"];
+
+  patches = [
+    (fetchurl {
+      url = "https://ftp.suse.com/pub/people/sbrabec/bzip2/for_downstream/bzip2-1.0.6.2-autoconfiscated.patch";
+      sha256 = "sha256-QMufl6ffJVVVVZespvkCbFpB6++R1lnq1687jEsUjr0=";
+    })
+  ];
+  # Fix up hardcoded version from the above patch, e.g. seen in bzip2.pc or libbz2.so.1.0.N
+  postPatch = ''
+    patch <<-EOF
+      --- configure.ac
+      +++ configure.ac
+      @@ -3,3 +3,3 @@
+      -AC_INIT([bzip2], [1.0.6], [Julian Seward <jseward@bzip.org>])
+      +AC_INIT([bzip2], [${version}], [Julian Seward <jseward@bzip.org>])
+       BZIP2_LT_CURRENT=1
+      -BZIP2_LT_REVISION=6
+      +BZIP2_LT_REVISION=${lib.versions.patch version}
+    EOF
+  '';
+
+  strictDeps = true;
+  nativeBuildInputs = [ autoreconfHook ];
+
+  outputs = [ "bin" "dev" "out" "man" ];
+
+  configureFlags = lib.concatLists [
+    (lib.optional enableStatic "--enable-static")
+    (lib.optional (!enableShared) "--disable-shared")
+  ];
+
+  dontDisableStatic = enableStatic;
+
+  enableParallelBuilding = true;
+
+  postInstall = ''
+    ln -s $out/lib/libbz2.so.1.0.* $out/lib/libbz2.so.1.0
+  '';
+
+  passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
+
+  meta = with lib; {
+    description = "High-quality data compression program";
+    homepage = "https://www.sourceware.org/bzip2";
+    changelog = "https://sourceware.org/git/?p=bzip2.git;a=blob;f=CHANGES;hb=HEAD";
+    license = licenses.bsdOriginal;
+    pkgConfigModules = [ "bzip2" ];
+    platforms = platforms.all;
+    maintainers = with maintainers; [ mic92 ];
+  };
+})
diff --git a/nixpkgs/pkgs/tools/compression/bzip3/default.nix b/nixpkgs/pkgs/tools/compression/bzip3/default.nix
new file mode 100644
index 000000000000..135b253229ad
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/bzip3/default.nix
@@ -0,0 +1,50 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, autoreconfHook
+, pkg-config
+, testers
+}:
+
+stdenv.mkDerivation (finalAttrs: {
+  pname = "bzip3";
+  version = "1.4.0";
+
+  outputs = [ "bin" "dev" "out" ];
+
+  src = fetchFromGitHub {
+    owner = "kspalaiologos";
+    repo = "bzip3";
+    rev = finalAttrs.version;
+    hash = "sha256-UVCZWcjlueKSGYqdm7oiJ5i7/irkWv7IOyeCWT2r4sk=";
+  };
+
+  postPatch = ''
+    echo -n "${finalAttrs.version}" > .tarball-version
+    patchShebangs build-aux
+
+    # build-aux/ax_subst_man_date.m4 calls git if the file exists
+    rm .gitignore
+  '';
+
+  nativeBuildInputs = [
+    autoreconfHook
+    pkg-config
+  ];
+
+  configureFlags = [
+    "--disable-arch-native"
+  ] ++ lib.optionals stdenv.isDarwin [ "--disable-link-time-optimization" ];
+
+  passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
+
+  meta = {
+    description = "A better and stronger spiritual successor to BZip2";
+    homepage = "https://github.com/kspalaiologos/bzip3";
+    changelog = "https://github.com/kspalaiologos/bzip3/blob/${finalAttrs.src.rev}/NEWS";
+    license = lib.licenses.lgpl3Plus;
+    maintainers = with lib.maintainers; [ dotlambda ];
+    pkgConfigModules = [ "bzip3" ];
+    platforms = lib.platforms.unix;
+  };
+})
diff --git a/nixpkgs/pkgs/tools/compression/crabz/default.nix b/nixpkgs/pkgs/tools/compression/crabz/default.nix
new file mode 100644
index 000000000000..f8cb155f272e
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/crabz/default.nix
@@ -0,0 +1,30 @@
+{ lib
+, rustPlatform
+, fetchFromGitHub
+, cmake
+}:
+
+rustPlatform.buildRustPackage rec {
+  pname = "crabz";
+  version = "0.8.1";
+
+  src = fetchFromGitHub {
+    owner = "sstadick";
+    repo = pname;
+    rev = "v${version}";
+    sha256 = "sha256-w/e0NFmBsYNEECT+2zHEm/UUpp5LxPYr0BdKikT2o1M=";
+  };
+
+  cargoSha256 = "sha256-9VOJeRvyudZSCaUZ1J9gHMEoWXEnEhCZPxvfYGRKzj0=";
+
+  nativeBuildInputs = [ cmake ];
+
+  meta = with lib; {
+    description = "A cross platform, fast, compression and decompression tool";
+    homepage = "https://github.com/sstadick/crabz";
+    changelog = "https://github.com/sstadick/crabz/blob/v${version}/CHANGELOG.md";
+    license = with licenses; [ unlicense /* or */ mit ];
+    maintainers = with maintainers; [ figsoda ];
+    mainProgram = "crabz";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/dejsonlz4/default.nix b/nixpkgs/pkgs/tools/compression/dejsonlz4/default.nix
new file mode 100644
index 000000000000..51c5d485cfa9
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/dejsonlz4/default.nix
@@ -0,0 +1,31 @@
+{ lib, stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  pname = "dejsonlz4";
+  version = "1.1";
+
+  src = fetchFromGitHub {
+    owner = "avih";
+    repo = pname;
+    rev = "v${version}";
+    sha256 = "0ggs69qamaama5mid07mhp95m1x42wljdb953lrwfr7p8p6f8czh";
+  };
+
+  buildPhase = ''
+    ${stdenv.cc.targetPrefix}cc -o dejsonlz4 src/dejsonlz4.c src/lz4.c
+  '';
+
+  installPhase = ''
+    mkdir -p $out/bin/
+    cp dejsonlz4 $out/bin/
+  '';
+
+  meta = with lib; {
+    description = "Decompress Mozilla Firefox bookmarks backup files";
+    homepage = "https://github.com/avih/dejsonlz4";
+    license = licenses.bsd2;
+    maintainers = with maintainers; [ mt-caret ];
+    platforms = platforms.all;
+    mainProgram = "dejsonlz4";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/dtrx/default.nix b/nixpkgs/pkgs/tools/compression/dtrx/default.nix
new file mode 100644
index 000000000000..9890112171d8
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/dtrx/default.nix
@@ -0,0 +1,56 @@
+{ lib
+, fetchFromGitHub
+, gitUpdater
+, python3Packages
+, gnutar
+, unzip
+, lhasa
+, rpm
+, binutils
+, cpio
+, gzip
+, p7zip
+, cabextract
+, unrar
+, unshield
+, bzip2
+, xz
+, lzip
+, unzipSupport ? false
+, unrarSupport ? false
+}:
+
+python3Packages.buildPythonApplication rec {
+  pname = "dtrx";
+  version = "8.5.3";
+
+  src = fetchFromGitHub {
+    owner = "dtrx-py";
+    repo = "dtrx";
+    rev = version;
+    sha256 = "sha256-LB3F6jcqQPRsjFO4L2fPAPnacDAdtcaadgGbwXA9LAw=";
+  };
+
+  makeWrapperArgs =
+    let
+      archivers = lib.makeBinPath (
+        [ gnutar lhasa rpm binutils cpio gzip p7zip cabextract unshield bzip2 xz lzip ]
+        ++ lib.optional (unzipSupport) unzip
+        ++ lib.optional (unrarSupport) unrar
+      );
+    in [
+      ''--prefix PATH : "${archivers}"''
+    ];
+
+  nativeBuildInputs = [ python3Packages.invoke ];
+
+  passthru.updateScript = gitUpdater { };
+
+  meta = with lib; {
+    description = "Do The Right Extraction: A tool for taking the hassle out of extracting archives";
+    homepage = "https://github.com/dtrx-py/dtrx";
+    license = licenses.gpl3Plus;
+    maintainers = [ ];
+    mainProgram = "dtrx";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/efficient-compression-tool/default.nix b/nixpkgs/pkgs/tools/compression/efficient-compression-tool/default.nix
new file mode 100644
index 000000000000..a4f4b9fd40da
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/efficient-compression-tool/default.nix
@@ -0,0 +1,45 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, boost
+, cmake
+, nasm
+, libpng
+}:
+
+stdenv.mkDerivation rec {
+  pname = "efficient-compression-tool";
+  version = "0.9.1";
+
+  src = fetchFromGitHub {
+    owner = "fhanau";
+    repo = "Efficient-Compression-Tool";
+    rev = "v${version}";
+    sha256 = "sha256-TSV5QXf6GuHAwQrde3Zo9MA1rtpAhtRg0UTzMkBnHB8=";
+    fetchSubmodules = true;
+  };
+
+  nativeBuildInputs = [ cmake nasm ];
+
+  patches = [ ./use-nixpkgs-libpng.patch ];
+
+  buildInputs = [ boost libpng  ];
+
+  cmakeDir = "../src";
+
+  cmakeFlags = [ "-DECT_FOLDER_SUPPORT=ON" ];
+
+  CXXFLAGS = [
+    # GCC 13: error: 'uint32_t' does not name a type
+    "-include cstdint"
+  ];
+
+  meta = with lib; {
+    description = "Fast and effective C++ file optimizer";
+    homepage = "https://github.com/fhanau/Efficient-Compression-Tool";
+    license = licenses.asl20;
+    maintainers = [ maintainers.lunik1 ];
+    platforms = platforms.linux;
+    mainProgram = "ect";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/efficient-compression-tool/use-nixpkgs-libpng.patch b/nixpkgs/pkgs/tools/compression/efficient-compression-tool/use-nixpkgs-libpng.patch
new file mode 100644
index 000000000000..f165b2b95506
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/efficient-compression-tool/use-nixpkgs-libpng.patch
@@ -0,0 +1,108 @@
+diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
+index d18843c..a9df1fb 100644
+--- a/src/CMakeLists.txt
++++ b/src/CMakeLists.txt
+@@ -8,11 +8,6 @@ if(NOT CMAKE_BUILD_TYPE)
+ 	set(CMAKE_BUILD_TYPE Release)
+ endif()
+ 
+-# Check that submodules are present only if source was downloaded with git
+-if(EXISTS "${CMAKE_SOURCE_DIR}/../.git" AND NOT EXISTS "${CMAKE_SOURCE_DIR}/../src/libpng/README")
+-    message (FATAL_ERROR "Submodules are not initialized. Run \n\tgit submodule update --init --recursive\n within the repository")
+-endif()
+-
+ add_executable(ect
+ 	main.cpp
+ 	gztools.cpp
+@@ -56,7 +51,6 @@ add_subdirectory(lodepng EXCLUDE_FROM_ALL)
+ add_subdirectory(miniz EXCLUDE_FROM_ALL)
+ add_subdirectory(zlib EXCLUDE_FROM_ALL)
+ add_subdirectory(zopfli EXCLUDE_FROM_ALL)
+-file(COPY ${CMAKE_SOURCE_DIR}/pngusr.h DESTINATION ${CMAKE_SOURCE_DIR}/libpng/)
+ add_subdirectory(optipng EXCLUDE_FROM_ALL)
+ # Mozjpeg changes the install prefix if it thinks the current is defaulted
+ set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT FALSE)
+diff --git a/src/Makefile b/src/Makefile
+index cc24367..7aa9f0a 100755
+--- a/src/Makefile
++++ b/src/Makefile
+@@ -18,7 +18,7 @@ CXXSRC = support.cpp zopflipng.cpp zopfli/deflate.cpp zopfli/zopfli_gzip.cpp zop
+ lodepng/lodepng.cpp lodepng/lodepng_util.cpp optipng/codec.cpp optipng/optipng.cpp jpegtran.cpp gztools.cpp \
+ leanify/zip.cpp leanify/leanify.cpp
+ 
+-.PHONY: libpng mozjpeg deps bin all install
++.PHONY: mozjpeg deps bin all install
+ all: deps bin
+ 
+ bin: deps
+@@ -33,9 +33,6 @@ libz.a:
+ 	cd zlib/; \
+ 	$(CC) $(UCFLAGS) -c adler32.c crc32.c deflate.c inffast.c inflate.c inftrees.c trees.c zutil.c gzlib.c gzread.c; \
+ 	ar rcs ../libz.a adler32.o crc32.o deflate.o inffast.o inflate.o inftrees.o trees.o zutil.o gzlib.o gzread.o
+-libpng:
+-	cp pngusr.h libpng/pngusr.h
+-	make -C libpng/ -f scripts/makefile.linux-opt CC="$(CC)" CFLAGS="$(UCFLAGS) -DPNG_USER_CONFIG -Wno-macro-redefined" libpng.a
+ mozjpeg:
+ 	cd mozjpeg/; \
+ 	export CC="$(CC)"; \
+diff --git a/src/optipng/CMakeLists.txt b/src/optipng/CMakeLists.txt
+index 1037a20..3c751e9 100644
+--- a/src/optipng/CMakeLists.txt
++++ b/src/optipng/CMakeLists.txt
+@@ -16,16 +16,14 @@ add_library(optipng
+ add_library(optipng::optipng ALIAS optipng)
+ 
+ #make sure that we are using custom zlib and custom libpng options
+-set(PNG_BUILD_ZLIB ON CACHE BOOL "use custom zlib within libpng" FORCE)
+ set(ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../zlib/ CACHE FILEPATH "custom zlib directory" FORCE)
+ if(NOT WIN32)
+ 	add_compile_options(-Wno-macro-redefined)
+ endif()
+ add_compile_definitions(PNG_USER_CONFIG)
+ 
+-add_subdirectory(../libpng libpng EXCLUDE_FROM_ALL)
+ target_link_libraries(optipng
+-	png_static)
++	png)
+ 
+ # libpng generates some header files that we need to be able to include
+ target_include_directories(optipng
+diff --git a/src/optipng/image.h b/src/optipng/image.h
+index c439f84..8255fa0 100755
+--- a/src/optipng/image.h
++++ b/src/optipng/image.h
+@@ -13,7 +13,7 @@
+ #ifndef OPNGCORE_IMAGE_H
+ #define OPNGCORE_IMAGE_H
+ 
+-#include "../libpng/png.h"
++#include <png.h>
+ 
+ #ifdef __cplusplus
+ extern "C" {
+diff --git a/src/optipng/opngreduc/opngreduc.h b/src/optipng/opngreduc/opngreduc.h
+index a7e6553..06ef956 100755
+--- a/src/optipng/opngreduc/opngreduc.h
++++ b/src/optipng/opngreduc/opngreduc.h
+@@ -13,7 +13,7 @@
+ 
+ #include <stdbool.h>
+ 
+-#include "../../libpng/png.h"
++#include <png.h>
+ 
+ 
+ #ifdef __cplusplus
+diff --git a/src/optipng/trans.h b/src/optipng/trans.h
+index a2f7f3e..c0e8dc4 100755
+--- a/src/optipng/trans.h
++++ b/src/optipng/trans.h
+@@ -13,7 +13,7 @@
+ #ifndef OPNGTRANS_TRANS_H
+ #define OPNGTRANS_TRANS_H
+ 
+-#include "../libpng/png.h"
++#include <png.h>
+ 
+ #ifdef __cplusplus
+ extern "C" {
diff --git a/nixpkgs/pkgs/tools/compression/flips/default.nix b/nixpkgs/pkgs/tools/compression/flips/default.nix
new file mode 100644
index 000000000000..6ee1c03cabce
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/flips/default.nix
@@ -0,0 +1,32 @@
+{ lib, stdenv, fetchFromGitHub, gtk3, libdivsufsort, pkg-config, wrapGAppsHook }:
+
+stdenv.mkDerivation {
+  pname = "flips";
+  version = "unstable-2023-03-15";
+
+  src = fetchFromGitHub {
+    owner = "Alcaro";
+    repo = "Flips";
+    rev = "fdd5c6e34285beef5b9be759c9b91390df486c66";
+    hash = "sha256-uuHgpt7aWqiMTUILm5tAEGGeZrls3g/DdylYQgsfpTw=";
+  };
+
+  nativeBuildInputs = [ pkg-config wrapGAppsHook ];
+  buildInputs = [ gtk3 libdivsufsort ];
+  patches = [ ./use-system-libdivsufsort.patch ];
+  makeFlags = [ "PREFIX=${placeholder "out"}" ];
+  buildPhase = ''
+    runHook preBuild
+    ./make.sh
+    runHook postBuild
+  '';
+
+  meta = with lib; {
+    description = "A patcher for IPS and BPS files";
+    homepage = "https://github.com/Alcaro/Flips";
+    license = licenses.gpl3Plus;
+    maintainers = [ maintainers.xfix ];
+    platforms = platforms.linux;
+    mainProgram = "flips";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/flips/use-system-libdivsufsort.patch b/nixpkgs/pkgs/tools/compression/flips/use-system-libdivsufsort.patch
new file mode 100644
index 000000000000..d621fe3a9f40
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/flips/use-system-libdivsufsort.patch
@@ -0,0 +1,15 @@
+diff --git a/Makefile b/Makefile
+index b3d5aeb..a5acc08 100644
+--- a/Makefile
++++ b/Makefile
+@@ -83,9 +83,7 @@ endif
+ 
+ MOREFLAGS := $(CFLAGS_$(TARGET))
+ 
+-DIVSUF := $(SRCDIR)/libdivsufsort-2.0.1
+-SOURCES += $(DIVSUF)/lib/divsufsort.c $(DIVSUF)/lib/sssort.c $(DIVSUF)/lib/trsort.c
+-MOREFLAGS += -I$(DIVSUF)/include -DHAVE_CONFIG_H -D__STDC_FORMAT_MACROS
++MOREFLAGS += -ldivsufsort
+ 
+ ifeq ($(TARGET),gtk)
+   CFLAGS_G += -fopenmp
diff --git a/nixpkgs/pkgs/tools/compression/gzip/default.nix b/nixpkgs/pkgs/tools/compression/gzip/default.nix
new file mode 100644
index 000000000000..b48e2696f09c
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/gzip/default.nix
@@ -0,0 +1,72 @@
+{ lib, stdenv
+, fetchurl
+, makeWrapper
+, xz
+}:
+
+# Note: this package is used for bootstrapping fetchurl, and thus
+# cannot use fetchpatch! All mutable patches (generated by GitHub or
+# cgit) that are needed here should be included directly in Nixpkgs as
+# files.
+
+stdenv.mkDerivation rec {
+  pname = "gzip";
+  version = "1.13";
+
+  src = fetchurl {
+    url = "mirror://gnu/gzip/${pname}-${version}.tar.xz";
+    hash = "sha256-dFTraTXbF8ZlVXbC4bD6vv04tNCTbg+H9IzQYs6RoFc=";
+  };
+
+  outputs = [ "out" "man" "info" ];
+
+  enableParallelBuilding = true;
+
+  nativeBuildInputs = [ xz.bin makeWrapper ];
+
+  makeFlags = [
+    "SHELL=/bin/sh"
+    "GREP=grep"
+    # gzip 1.12 doesn't build `zless` unless it can find `less`, but we
+    # can avoid having `less` as a build input if we just override these.
+    "ZLESS_MAN=zless.1"
+    "ZLESS_PROG=zless"
+  ];
+
+  # Many gzip executables are shell scripts that depend upon other gzip
+  # executables being in $PATH.  Rather than try to re-write all the
+  # internal cross-references, just add $out/bin to PATH at the top of
+  # all the executables that are shell scripts.
+  preFixup = ''
+    sed -i '1{;/#!\/bin\/sh/aPATH="'$out'/bin:$PATH"
+    }' $out/bin/*
+  ''
+  # run gzip with "-n" when $GZIP_NO_TIMESTAMPS (set by stdenv's setup.sh) is set to stop gzip from adding timestamps
+  # to archive headers: https://github.com/NixOS/nixpkgs/issues/86348
+  # if changing so that there's no longer a .gzip-wrapped then update copy in make-bootstrap-tools.nix
+  + ''
+    wrapProgram $out/bin/gzip \
+      --add-flags "\''${GZIP_NO_TIMESTAMPS:+-n}"
+  '';
+
+  meta = {
+    homepage = "https://www.gnu.org/software/gzip/";
+    description = "GNU zip compression program";
+
+    longDescription =
+      ''gzip (GNU zip) is a popular data compression program written by
+        Jean-loup Gailly for the GNU project.  Mark Adler wrote the
+        decompression part.
+
+        We developed this program as a replacement for compress because of
+        the Unisys and IBM patents covering the LZW algorithm used by
+        compress.  These patents made it impossible for us to use compress,
+        and we needed a replacement.  The superior compression ratio of gzip
+        is just a bonus.
+      '';
+
+    platforms = lib.platforms.all;
+
+    license = lib.licenses.gpl3Plus;
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/gzrt/default.nix b/nixpkgs/pkgs/tools/compression/gzrt/default.nix
new file mode 100644
index 000000000000..59d87cf4f341
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/gzrt/default.nix
@@ -0,0 +1,27 @@
+{ lib, stdenv, fetchurl, zlib }:
+
+stdenv.mkDerivation rec {
+  pname = "gzrt";
+  version = "0.8";
+
+  src = fetchurl {
+    url = "https://www.urbanophile.com/arenn/coding/gzrt/gzrt-${version}.tar.gz";
+    sha256 = "1vhzazj47xfpbfhzkwalz27cc0n5gazddmj3kynhk0yxv99xrdxh";
+  };
+
+  buildInputs = [ zlib ];
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp gzrecover $out/bin
+  '';
+
+  meta = with lib; {
+    homepage = "https://www.urbanophile.com/arenn/hacking/gzrt/";
+    description = "The gzip Recovery Toolkit";
+    maintainers = with maintainers; [ ];
+    mainProgram = "gzrecover";
+    license = licenses.gpl2Plus;
+    platforms = platforms.unix;
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/hacpack/default.nix b/nixpkgs/pkgs/tools/compression/hacpack/default.nix
new file mode 100644
index 000000000000..8d44660898cf
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/hacpack/default.nix
@@ -0,0 +1,34 @@
+{ lib, stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  pname = "hacpack";
+  version = "1.36";
+
+  src = fetchFromGitHub {
+    owner = "The-4n";
+    repo = "hacpack";
+    rev = "v${version}";
+    sha256 = "0d846l36w1n9rxv79fbyhl2zdbqhlgrvk21b9vzr9x77yki89ygs";
+  };
+
+  preConfigure = ''
+    mv config.mk.template config.mk
+  '';
+
+  makeFlags = [ "CC=${stdenv.cc.targetPrefix}cc" ];
+  enableParallelBuilding = true;
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp ./hacpack $out/bin
+  '';
+
+  meta = with lib; {
+    homepage = "https://github.com/The-4n/hacPack";
+    description = "Make and repack Nintendo Switch NCAs/NSPs";
+    license = licenses.gpl2Only;
+    maintainers = [ maintainers.ivar ];
+    platforms = platforms.linux;
+    mainProgram = "hacpack";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/hactool/default.nix b/nixpkgs/pkgs/tools/compression/hactool/default.nix
new file mode 100644
index 000000000000..11adbe3ced1b
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/hactool/default.nix
@@ -0,0 +1,36 @@
+{ lib, stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  pname = "hactool";
+  version = "1.4.0";
+
+  src = fetchFromGitHub {
+    owner = "SciresM";
+    repo = "hactool";
+    rev = version;
+    sha256 = "0305ngsnwm8npzgyhyifasi4l802xnfz19r0kbzzniirmcn4082d";
+  };
+
+  patches = [ ./musl-compat.patch ];
+
+  preBuild = ''
+    mv config.mk.template config.mk
+  '';
+
+  makeFlags = [ "CC=${stdenv.cc.targetPrefix}cc" ];
+  enableParallelBuilding = true;
+
+  installPhase = ''
+    install -D hactool $out/bin/hactool
+  '';
+
+  meta = with lib; {
+    homepage = "https://github.com/SciresM/hactool";
+    description = "A tool to manipulate common file formats for the Nintendo Switch";
+    longDescription = "A tool to view information about, decrypt, and extract common file formats for the Nintendo Switch, especially Nintendo Content Archives";
+    license = licenses.isc;
+    maintainers = with maintainers; [ ivar ];
+    platforms = platforms.unix;
+    mainProgram = "hactool";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/hactool/musl-compat.patch b/nixpkgs/pkgs/tools/compression/hactool/musl-compat.patch
new file mode 100644
index 000000000000..37d596f183fb
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/hactool/musl-compat.patch
@@ -0,0 +1,13 @@
+diff --git a/main.c b/main.c
+index 07f53cb..f2265df 100644
+--- a/main.c
++++ b/main.c
+@@ -369,7 +369,7 @@ int main(int argc, char **argv) {
+                     return EXIT_FAILURE;
+                 }
+                 nca_ctx.tool_ctx->base_file_type = BASEFILE_FAKE;
+-                nca_ctx.tool_ctx->base_file++; /* Guarantees base_file != NULL. I'm so sorry. */
++                if (!nca_ctx.tool_ctx->base_file) nca_ctx.tool_ctx->base_file = (FILE*) 1;
+                 break;
+             case 32:
+                 tool_ctx.action |= ACTION_ONLYUPDATEDROMFS;
diff --git a/nixpkgs/pkgs/tools/compression/heatshrink/default.nix b/nixpkgs/pkgs/tools/compression/heatshrink/default.nix
new file mode 100644
index 000000000000..b5cfb92247af
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/heatshrink/default.nix
@@ -0,0 +1,49 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, cmake
+, fetchpatch
+}:
+
+stdenv.mkDerivation rec {
+  pname = "heatshrink";
+  version = "0.4.1";
+
+  src = fetchFromGitHub {
+    owner = "atomicobject";
+    repo = "heatshrink";
+    rev = "v${version}";
+    hash = "sha256-Nm9/+JFMDXY1N90hmNFGh755V2sXSRQ4VBN9f8TcsGk=";
+  };
+
+  patches = [
+    # Add CMake build script, wanted by prusa-slicer and libbgcode, which are the only users of this library.
+    (fetchpatch {
+      url = "https://github.com/atomicobject/heatshrink/commit/0886e9ca76552b8e325841e2b820b4563e5d5aba.patch";
+      hash = "sha256-13hy4+/RDaaKgQcdaSbACvMfElUIskvJ+owXqm40feY=";
+    })
+  ];
+
+  nativeBuildInputs = [
+    cmake
+  ];
+
+  doInstallCheck = true;
+  installCheckPhase = ''
+    runHook preInstallCheck
+    echo "Hello world" | \
+      $out/bin/heatshrink -e - | \
+      $out/bin/heatshrink -d - | \
+      grep "Hello world"
+    runHook postInstallCheck
+  '';
+
+  meta = with lib; {
+    description = "A data compression/decompression library for embedded/real-time systems";
+    homepage = "https://github.com/atomicobject/heatshrink";
+    license = licenses.isc;
+    maintainers = with maintainers; [ fgaz ];
+    platforms = platforms.all;
+    mainProgram = "heatshrink";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/imagelol/default.nix b/nixpkgs/pkgs/tools/compression/imagelol/default.nix
new file mode 100644
index 000000000000..950b12826b33
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/imagelol/default.nix
@@ -0,0 +1,59 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, fetchpatch
+, cmake
+}:
+
+stdenv.mkDerivation rec {
+  pname = "imagelol";
+  version = "0.2";
+
+  src = fetchFromGitHub {
+    owner = "MCRedstoner2004";
+    repo = pname;
+    rev = "v${version}";
+    sha256 = "0978zdrfj41jsqm78afyyd1l64iki9nwjvhd8ynii1b553nn4dmd";
+    fetchSubmodules = true;
+  };
+
+  patches = [
+    # upstream gcc-12 compatibility fix
+    (fetchpatch {
+      name = "gcc-12.patch";
+      url = "https://github.com/MCredstoner2004/ImageLOL/commit/013fb1f901d88f5fd21a896bfab47c7fff0737d7.patch";
+      hash = "sha256-RVaG2xbUqE4CxqI2lhvug2qihT6A8vN+pIfK58CXLDw=";
+      includes = [ "imagelol/ImageLOL.inl" ];
+      # change lib/ for imagelol
+      stripLen = 2;
+      extraPrefix = "imagelol/";
+    })
+  ];
+
+
+  # fix for case-sensitive filesystems
+  # https://github.com/MCredstoner2004/ImageLOL/issues/1
+  postPatch = ''
+    mv imagelol src
+    substituteInPlace CMakeLists.txt \
+      --replace 'add_subdirectory("imagelol")' 'add_subdirectory("src")'
+  '';
+
+  nativeBuildInputs = [ cmake ];
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp ./ImageLOL $out/bin
+  '';
+
+  cmakeFlags = lib.optional (stdenv.isDarwin && stdenv.isAarch64) "-DPNG_ARM_NEON=off";
+
+  meta = with lib; {
+    homepage = "https://github.com/MCredstoner2004/ImageLOL";
+    description = "Simple program to store a file into a PNG image";
+    license = licenses.mit;
+    maintainers = [ maintainers.ivar ];
+    platforms = platforms.unix;
+    mainProgram = "ImageLOL";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/keka/default.nix b/nixpkgs/pkgs/tools/compression/keka/default.nix
new file mode 100644
index 000000000000..71e979fa0c20
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/keka/default.nix
@@ -0,0 +1,38 @@
+{ lib
+, stdenvNoCC
+, fetchurl
+, unzip
+, makeWrapper
+}:
+stdenvNoCC.mkDerivation (finalAttrs: {
+  pname = "keka";
+  version = "1.3.2";
+
+  src = fetchurl {
+    url = "https://github.com/aonez/Keka/releases/download/v${finalAttrs.version}/Keka-${finalAttrs.version}.zip";
+    sha256 = "0id8j639kba5yc0z34lgvadzgv9z9s2573nn6dx9m6gd8qpnk2x7";
+  };
+  dontUnpack = true;
+
+  nativeBuildInputs = [ unzip makeWrapper ];
+
+  installPhase = ''
+    runHook preInstall
+
+    mkdir -p $out/Applications $out/bin
+    unzip -d $out/Applications $src
+    makeWrapper $out/Applications/Keka.app/Contents/MacOS/Keka $out/bin/keka \
+      --add-flags "--cli"
+
+    runHook postInstall
+  '';
+
+  meta = with lib; {
+    description = "macOS file archiver";
+    homepage = "https://www.keka.io";
+    license = licenses.unfree;
+    sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
+    maintainers = with maintainers; [ emilytrau Enzime ];
+    platforms = platforms.darwin;
+  };
+})
diff --git a/nixpkgs/pkgs/tools/compression/kzipmix/default.nix b/nixpkgs/pkgs/tools/compression/kzipmix/default.nix
new file mode 100644
index 000000000000..bde65af03e90
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/kzipmix/default.nix
@@ -0,0 +1,27 @@
+{ lib, stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  pname = "kzipmix";
+  version = "20200115";
+
+  src = fetchurl {
+    url = "http://static.jonof.id.au/dl/kenutils/kzipmix-${version}-linux.tar.gz";
+    sha256 = "sha256-ePgye0D6/ED53zx6xffLnYhkjed7SPU4BLOZQr9E3yA=";
+  };
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp amd64/{kzip,zipmix} $out/bin
+
+    patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux.so.2 $out/bin/kzip
+    patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux.so.2 $out/bin/zipmix
+  '';
+
+  meta = with lib; {
+    description = "A tool that aggressively optimizes the sizes of Zip archives";
+    sourceProvenance = with sourceTypes; [ binaryNativeCode ];
+    license = licenses.unfree;
+    homepage = "http://advsys.net/ken/utils.htm";
+    maintainers = [ maintainers.sander ];
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/lbzip2/default.nix b/nixpkgs/pkgs/tools/compression/lbzip2/default.nix
new file mode 100644
index 000000000000..2e7557a310e5
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/lbzip2/default.nix
@@ -0,0 +1,40 @@
+{ lib, stdenv, fetchFromGitHub, fetchpatch, gnulib, perl, autoconf, automake }:
+
+stdenv.mkDerivation rec {
+  pname = "lbzip2";
+  version = "2.5";
+
+  src = fetchFromGitHub {
+    owner = "kjn";
+    repo = "lbzip2";
+    rev = "v${version}";
+    sha256 = "1h321wva6fp6khz6x0i6rqb76xh327nw6v5jhgjpcckwdarj5jv8";
+  };
+
+  patches = [
+    # This avoids an implicit function declaration when building gnulib's
+    # xmalloc.c, addressing a build failure with future compiler version.
+    # https://github.com/kjn/lbzip2/pull/33
+    (fetchpatch {
+      name = "GNULIB_XALLOC_DIE.patch";
+      url = "https://github.com/kjn/lbzip2/commit/32b5167940ec817e454431956040734af405a9de.patch";
+      hash = "sha256-YNgmkh4bksIq5kBgZP+8o97aMm9CzFZldfUW6L5DGXk=";
+    })
+  ];
+
+  buildInputs = [ gnulib perl ];
+  nativeBuildInputs = [ autoconf automake ];
+
+  preConfigure = ''
+    substituteInPlace configure.ac --replace 'AC_PREREQ([2.63])' 'AC_PREREQ(2.64)'
+    ./build-aux/autogen.sh
+  '';
+
+  meta = with lib; {
+    homepage = "https://github.com/kjn/lbzip2"; # Formerly http://lbzip2.org/
+    description = "Parallel bzip2 compression utility";
+    license = licenses.gpl3;
+    maintainers = with maintainers; [ abbradar ];
+    platforms = platforms.unix;
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/lhasa/default.nix b/nixpkgs/pkgs/tools/compression/lhasa/default.nix
new file mode 100644
index 000000000000..9ced4a9b7bfb
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/lhasa/default.nix
@@ -0,0 +1,25 @@
+{ lib, stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  pname = "lhasa";
+  version = "0.4.0";
+
+  src = fetchurl {
+    url = "https://soulsphere.org/projects/lhasa/lhasa-${version}.tar.gz";
+    sha256 = "sha256-p/yIPDBMUIVi+5P6MHpMNCsMiG/MJl8ouS3Aw5IgxbM=";
+  };
+
+  meta = with lib; {
+    description = "Free Software replacement for the Unix LHA tool";
+    longDescription = ''
+      Lhasa is a Free Software replacement for the Unix LHA tool, for
+      decompressing .lzh (LHA / LHarc) and .lzs (LArc) archives. The backend for
+      the tool is a library, so that it can be reused for other purposes.
+    '';
+    license = licenses.isc;
+    homepage = "http://fragglet.github.io/lhasa";
+    maintainers = [ maintainers.sander ];
+    mainProgram = "lha";
+    platforms = platforms.unix;
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/lrzip/default.nix b/nixpkgs/pkgs/tools/compression/lrzip/default.nix
new file mode 100644
index 000000000000..3bb1e29f0347
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/lrzip/default.nix
@@ -0,0 +1,41 @@
+{ lib, stdenv, fetchFromGitHub, autoreconfHook, zlib, lzo, bzip2, lz4, nasm, perl }:
+
+let
+  inherit (stdenv.hostPlatform) isx86;
+in
+stdenv.mkDerivation rec {
+  pname = "lrzip";
+  version = "0.651";
+
+  src = fetchFromGitHub {
+    owner = "ckolivas";
+    repo = pname;
+    rev = "v${version}";
+    sha256 = "sha256-Mb324ojtLV0S10KhL7Vjf3DhSOtCy1pFMTzvLkTnpXM=";
+  };
+
+  postPatch = lib.optionalString stdenv.isDarwin ''
+    # Building the ASM/x86 directory creates an empty archive,
+    # which fails on darwin, so remove it
+    # https://github.com/ckolivas/lrzip/issues/193
+    # https://github.com/Homebrew/homebrew-core/pull/85360
+    substituteInPlace lzma/Makefile.am --replace "SUBDIRS = C ASM/x86" "SUBDIRS = C"
+    substituteInPlace configure.ac --replace "-f elf64" "-f macho64"
+  '';
+
+  nativeBuildInputs = [ autoreconfHook perl ] ++ lib.optionals isx86 [ nasm ];
+
+  buildInputs = [ zlib lzo bzip2 lz4 ];
+
+  configureFlags = lib.optionals (!isx86) [
+    "--disable-asm"
+  ];
+
+  meta = with lib; {
+    homepage = "http://ck.kolivas.org/apps/lrzip/";
+    description = "The CK LRZIP compression program (LZMA + RZIP)";
+    maintainers = with maintainers; [ ];
+    license = licenses.gpl2Plus;
+    platforms = platforms.unix;
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/lz4/default.nix b/nixpkgs/pkgs/tools/compression/lz4/default.nix
new file mode 100644
index 000000000000..f745f4f091ab
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/lz4/default.nix
@@ -0,0 +1,70 @@
+{ lib, stdenv, fetchFromGitHub, fetchpatch, valgrind
+, enableStatic ? stdenv.hostPlatform.isStatic
+, enableShared ? !stdenv.hostPlatform.isStatic
+}:
+
+stdenv.mkDerivation rec {
+  pname = "lz4";
+  version = "1.9.4";
+
+  src = fetchFromGitHub {
+    sha256 = "sha256-YiMCD3vvrG+oxBUghSrCmP2LAfAGZrEaKz0YoaQJhpI=";
+    rev = "v${version}";
+    repo = pname;
+    owner = pname;
+  };
+
+  patches = [
+    (fetchpatch { # https://github.com/lz4/lz4/pull/1162
+      name = "build-shared-no.patch";
+      url = "https://github.com/lz4/lz4/commit/851ef4b23c7cbf4ceb2ba1099666a8b5ec4fa195.patch";
+      sha256 = "sha256-P+/uz3m7EAmHgXF/1Vncc0uKKxNVq6HNIsElx0rGxpw=";
+    })
+  ];
+
+  # TODO(@Ericson2314): Separate binaries and libraries
+  outputs = [ "bin" "out" "dev" ];
+
+  buildInputs = lib.optional doCheck valgrind;
+
+  enableParallelBuilding = true;
+
+  makeFlags = [
+    "PREFIX=$(out)"
+    "INCLUDEDIR=$(dev)/include"
+    "BUILD_STATIC=${if enableStatic then "yes" else "no"}"
+    "BUILD_SHARED=${if enableShared then "yes" else "no"}"
+    "WINDRES:=${stdenv.cc.bintools.targetPrefix}windres"
+  ]
+    # TODO make full dictionary
+    ++ lib.optional stdenv.hostPlatform.isMinGW "TARGET_OS=MINGW"
+    ++ lib.optional stdenv.hostPlatform.isLinux "TARGET_OS=Linux"
+    ;
+
+  doCheck = false; # tests take a very long time
+  checkTarget = "test";
+
+  # TODO(@Ericson2314): Make resusable setup hook for this issue on Windows.
+  postInstall =
+    lib.optionalString stdenv.hostPlatform.isWindows ''
+      mv $out/bin/*.dll $out/lib
+      ln -s $out/lib/*.dll
+    ''
+    + ''
+      moveToOutput bin "$bin"
+    '';
+
+  meta = with lib; {
+    description = "Extremely fast compression algorithm";
+    longDescription = ''
+      Very fast lossless compression algorithm, providing compression speed
+      at 400 MB/s per core, with near-linear scalability for multi-threaded
+      applications. It also features an extremely fast decoder, with speed in
+      multiple GB/s per core, typically reaching RAM speed limits on
+      multi-core systems.
+    '';
+    homepage = "https://lz4.github.io/lz4/";
+    license = with licenses; [ bsd2 gpl2Plus ];
+    platforms = platforms.all;
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/lzbench/default.nix b/nixpkgs/pkgs/tools/compression/lzbench/default.nix
new file mode 100644
index 000000000000..c35f738b2bde
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/lzbench/default.nix
@@ -0,0 +1,28 @@
+{ lib, stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  pname = "lzbench";
+  version = "1.8.1";
+
+  src = fetchFromGitHub {
+    owner = "inikep";
+    repo = pname;
+    rev = "v${version}";
+    sha256 = "19zlvcjb1qg4fx30rrp6m650660y35736j8szvdxmqh9ipkisyia";
+  };
+
+  enableParallelBuilding = true;
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp lzbench $out/bin
+  '';
+
+  meta = with lib; {
+    inherit (src.meta) homepage;
+    description = "In-memory benchmark of open-source LZ77/LZSS/LZMA compressors";
+    license = licenses.free;
+    platforms = platforms.all;
+    mainProgram = "lzbench";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/lzfse/default.nix b/nixpkgs/pkgs/tools/compression/lzfse/default.nix
new file mode 100644
index 000000000000..e5f104a9aef2
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/lzfse/default.nix
@@ -0,0 +1,29 @@
+{ lib, stdenv, fetchFromGitHub, cmake }:
+
+stdenv.mkDerivation rec {
+  pname = "lzfse";
+  version = "1.0";
+
+  src = fetchFromGitHub {
+    owner = "lzfse";
+    repo = "lzfse";
+    rev = "lzfse-${version}";
+    sha256 = "1mfh6y6vpvxsdwmqmfbkqkwvxc0pz2dqqc72c6fk9sbsrxxaghd5";
+  };
+
+  nativeBuildInputs = [ cmake ];
+
+  meta = with lib; {
+    homepage = "https://github.com/lzfse/lzfse";
+    description = "a reference C implementation of the LZFSE compressor";
+    longDescription = ''
+      This is a reference C implementation of the LZFSE compressor introduced in the Compression library with OS X 10.11 and iOS 9.
+      LZFSE is a Lempel-Ziv style data compression algorithm using Finite State Entropy coding.
+      It targets similar compression rates at higher compression and decompression speed compared to deflate using zlib.
+    '';
+    platforms = platforms.unix;
+    license = licenses.bsd3;
+    maintainers = with maintainers; [ ];
+    mainProgram = "lzfse";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/lzham/default.nix b/nixpkgs/pkgs/tools/compression/lzham/default.nix
new file mode 100644
index 000000000000..5915d1439dff
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/lzham/default.nix
@@ -0,0 +1,27 @@
+{ lib, stdenv, fetchFromGitHub, cmake } :
+
+stdenv.mkDerivation rec {
+  pname = "lzham";
+  version = "1.0";
+
+  src = fetchFromGitHub {
+    owner = "richgel999";
+    repo = "lzham_codec";
+    rev = "v${lib.replaceStrings ["."] ["_"] version}_release";
+    sha256 = "14c1zvzmp1ylp4pgayfdfk1kqjb23xj4f7ll1ra7b18wjxc9ja1v";
+  };
+
+  nativeBuildInputs = [ cmake ];
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp ../bin_linux/lzhamtest $out/bin
+  '';
+
+  meta = with lib; {
+    description = "Lossless data compression codec with LZMA-like ratios but 1.5x-8x faster decompression speed";
+    homepage = "https://github.com/richgel999/lzham_codec";
+    license = with licenses; [ mit ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/lzip/default.nix b/nixpkgs/pkgs/tools/compression/lzip/default.nix
new file mode 100644
index 000000000000..3a5d62b8092d
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/lzip/default.nix
@@ -0,0 +1,42 @@
+{ lib, stdenv, fetchurl }:
+
+# Note: this package is used for bootstrapping fetchurl, and thus
+# cannot use fetchpatch! All mutable patches (generated by GitHub or
+# cgit) that are needed here should be included directly in Nixpkgs as
+# files.
+
+stdenv.mkDerivation rec {
+  pname = "lzip";
+  version = "1.24";
+  outputs = [ "out" "man" "info" ];
+
+  src = fetchurl {
+    url = "mirror://savannah/lzip/${pname}-${version}.tar.gz";
+    sha256 = "sha256-1CZZIpsQ4GbutugetnPN2JO2cuUS0mcZwtlZdVVspWw=";
+  };
+
+  patches = lib.optionals stdenv.hostPlatform.isMinGW [
+    ./mingw-install-exe-file.patch
+  ];
+
+  configureFlags = [
+    "CPPFLAGS=-DNDEBUG"
+    "CFLAGS=-O3"
+    "CXXFLAGS=-O3"
+    "CXX=${stdenv.cc.targetPrefix}c++"
+  ];
+
+  setupHook = ./lzip-setup-hook.sh;
+
+  doCheck = true;
+  enableParallelBuilding = true;
+
+  meta = with lib; {
+    homepage = "https://www.nongnu.org/lzip/lzip.html";
+    description = "A lossless data compressor based on the LZMA algorithm";
+    license = lib.licenses.gpl2Plus;
+    maintainers = with maintainers; [ vlaci ];
+    platforms = lib.platforms.all;
+    mainProgram = "lzip";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/lzip/lzip-setup-hook.sh b/nixpkgs/pkgs/tools/compression/lzip/lzip-setup-hook.sh
new file mode 100644
index 000000000000..092ad7737dd1
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/lzip/lzip-setup-hook.sh
@@ -0,0 +1,5 @@
+lzipUnpackCmdHook() {
+    [[ "$1" = *.tar.lz ]] && tar --lzip -xf "$1"
+}
+
+unpackCmdHooks+=(lzipUnpackCmdHook)
diff --git a/nixpkgs/pkgs/tools/compression/lzip/mingw-install-exe-file.patch b/nixpkgs/pkgs/tools/compression/lzip/mingw-install-exe-file.patch
new file mode 100644
index 000000000000..b2b4b2be067e
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/lzip/mingw-install-exe-file.patch
@@ -0,0 +1,13 @@
+diff --git a/Makefile.in b/Makefile.in
+index d07ad5a..1c15203 100644
+--- a/Makefile.in
++++ b/Makefile.in
+@@ -64,7 +64,7 @@ install-strip-compress : install-bin-strip install-info-compress install-man-com
+ 
+ install-bin : all
+ 	if [ ! -d "$(DESTDIR)$(bindir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(bindir)" ; fi
+-	$(INSTALL_PROGRAM) ./$(progname) "$(DESTDIR)$(bindir)/$(progname)"
++	$(INSTALL_PROGRAM) ./$(progname).exe "$(DESTDIR)$(bindir)/$(progname).exe"
+ 
+ install-bin-strip : all
+ 	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-bin
diff --git a/nixpkgs/pkgs/tools/compression/lziprecover/default.nix b/nixpkgs/pkgs/tools/compression/lziprecover/default.nix
new file mode 100644
index 000000000000..c3f2ca738c7d
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/lziprecover/default.nix
@@ -0,0 +1,32 @@
+{ lib, stdenv, fetchurl, lzip }:
+
+stdenv.mkDerivation rec {
+  pname = "lziprecover";
+  version = "1.24";
+
+  src = fetchurl {
+    url = "mirror://savannah/lzip/lziprecover/${pname}-${version}.tar.gz";
+    sha256 = "sha256-HWmc+u/pLrJiSjZSWAvK/gu7mP54GMJebegjvN0NRY8=";
+  };
+
+  configureFlags = [
+    "CPPFLAGS=-DNDEBUG"
+    "CFLAGS=-O3"
+    "CXXFLAGS=-O3"
+    "CXX=${stdenv.cc.targetPrefix}c++"
+  ];
+
+  doCheck = true;
+  nativeCheckInputs = [ lzip ];
+
+  enableParallelBuilding = true;
+
+  meta = with lib; {
+    homepage = "https://www.nongnu.org/lzip/lziprecover.html";
+    description = "Data recovery tool for lzip compressed files";
+    license = lib.licenses.gpl2Plus;
+    maintainers = with maintainers; [ vlaci ];
+    platforms = lib.platforms.all;
+    mainProgram = "lziprecover";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/lzop/default.nix b/nixpkgs/pkgs/tools/compression/lzop/default.nix
new file mode 100644
index 000000000000..64061647667a
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/lzop/default.nix
@@ -0,0 +1,22 @@
+{ lib, stdenv, fetchurl, lzo }:
+
+stdenv.mkDerivation rec {
+  pname = "lzop";
+  version = "1.04";
+
+  src = fetchurl {
+    url = "https://www.lzop.org/download/lzop-${version}.tar.gz";
+    sha256 = "0h9gb8q7y54m9mvy3jvsmxf21yx8fc3ylzh418hgbbv0i8mbcwky";
+  };
+
+  buildInputs = [ lzo ];
+
+  meta = with lib; {
+    homepage = "http://www.lzop.org";
+    description = "Fast file compressor";
+    maintainers = with maintainers; [ ];
+    license = licenses.gpl2;
+    platforms = platforms.unix;
+    mainProgram = "lzop";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/mozlz4a/default.nix b/nixpkgs/pkgs/tools/compression/mozlz4a/default.nix
new file mode 100644
index 000000000000..a9ab74bc7a59
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/mozlz4a/default.nix
@@ -0,0 +1,39 @@
+{ lib
+, stdenv
+, fetchurl
+, python3
+, runtimeShell
+}:
+
+stdenv.mkDerivation rec {
+  pname = "mozlz4a";
+  version = "2022-03-19";
+
+  src = fetchurl {
+    url = "https://gist.githubusercontent.com/Tblue/62ff47bef7f894e92ed5/raw/c12fce199a97ecb214eb913cc5d762eac2e92c57/mozlz4a.py";
+    hash = "sha256-Igj9u6TmV+nIuSg8gI8zD4hTb/Iiog/3aB3DDk0Lqkg=";
+  };
+
+  dontUnpack = true;
+
+  buildInputs = [ python3 python3.pkgs.lz4 ];
+
+  installPhase = ''
+    mkdir -p "$out/bin" "$out/${python3.sitePackages}/"
+    cp "${src}" "$out/${python3.sitePackages}/mozlz4a.py"
+
+    echo "#!${runtimeShell}" >> "$out/bin/mozlz4a"
+    echo "export PYTHONPATH='$PYTHONPATH'" >> "$out/bin/mozlz4a"
+    echo "'${python3}/bin/python' '$out/${python3.sitePackages}/mozlz4a.py' \"\$@\"" >> "$out/bin/mozlz4a"
+    chmod a+x "$out/bin/mozlz4a"
+  '';
+
+  meta = with lib; {
+    description = "MozLz4a compression/decompression utility";
+    license = licenses.bsd2;
+    maintainers = with maintainers; [ kira-bruneau pshirshov raskin ];
+    platforms = python3.meta.platforms;
+    homepage = "https://gist.github.com/Tblue/62ff47bef7f894e92ed5";
+    mainProgram = "mozlz4a";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/ncompress/default.nix b/nixpkgs/pkgs/tools/compression/ncompress/default.nix
new file mode 100644
index 000000000000..c4678cd96021
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/ncompress/default.nix
@@ -0,0 +1,27 @@
+{ lib, stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  pname = "ncompress";
+  version = "5.0";
+
+  src = fetchFromGitHub {
+    owner = "vapier";
+    repo = "ncompress";
+    rev = "v${version}";
+    sha256 = "sha256-Yhs3C5/kR7Ve56E84usYJprxIMAIwXVahLi1N9TIfj0=";
+  };
+
+  makeFlags = [ "PREFIX=$(out)" ];
+  installTargets = "install_core";
+
+  postInstall = ''
+    mv $out/bin/uncompress $out/bin/uncompress-ncompress
+  '';
+
+  meta = with lib; {
+    homepage = "http://ncompress.sourceforge.net/";
+    license = licenses.publicDomain;
+    description = "A fast, simple LZW file compressor";
+    platforms = platforms.unix;
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/nx2elf/default.nix b/nixpkgs/pkgs/tools/compression/nx2elf/default.nix
new file mode 100644
index 000000000000..a068788dc1d8
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/nx2elf/default.nix
@@ -0,0 +1,34 @@
+{ lib, stdenv, fetchFromGitHub, lz4 }:
+
+stdenv.mkDerivation rec {
+  pname = "nx2elf";
+  version = "unstable-2021-11-21";
+
+  src = fetchFromGitHub {
+    owner = "shuffle2";
+    repo = "nx2elf";
+    rev = "735aaa0648a5a6c996b48add9465db86524999f6";
+    sha256 = "sha256-cS8FFIEgDWva0j9JXhS+s7Y4Oh+mNhFaKRI7BF2hqvs=";
+  };
+
+  buildInputs = [ lz4 ];
+
+  postPatch = ''
+    # pkg-config is not supported, so we'll manually devendor lz4
+    cp ${lz4.src}/lib/lz4.{h,c} .
+  '';
+
+  installPhase = ''
+    mkdir -p $out/bin
+    install -D nx2elf $out/bin/nx2elf
+  '';
+
+  meta = with lib; {
+    homepage = "https://github.com/shuffle2/nx2elf";
+    description = "Convert Nintendo Switch executable files to ELFs";
+    license = licenses.unfree; # No license specified upstream
+    platforms = [ "x86_64-linux" ]; # Should work on Darwin as well, but this is untested. aarch64-linux fails.
+    maintainers = [ maintainers.ivar ];
+    mainProgram = "nx2elf";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/offzip/default.nix b/nixpkgs/pkgs/tools/compression/offzip/default.nix
new file mode 100644
index 000000000000..e756d4257264
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/offzip/default.nix
@@ -0,0 +1,33 @@
+{ lib
+, stdenv
+, fetchzip
+, zlib
+}:
+
+stdenv.mkDerivation rec {
+  pname = "offzip";
+  version = "0.4.1";
+
+  src = fetchzip {
+    url = "https://web.archive.org/web/20230419080810/https://aluigi.altervista.org/mytoolz/offzip.zip";
+    hash = "sha256-dmYeSdtNvx6FBuyCdiu+q1ExEfgN8fDO8coyJmFrjKY=";
+    stripRoot = false;
+  };
+
+  buildInputs = [
+    zlib
+  ];
+
+  makeFlags = [
+    "PREFIX=${placeholder "out"}"
+  ];
+
+  meta = with lib; {
+    description = "A tool to unpack the zip data contained in any type of file";
+    homepage = "https://aluigi.altervista.org/mytoolz.htm#offzip";
+    license = lib.licenses.gpl2Plus;
+    maintainers = with maintainers; [ r-burns ];
+    platforms = platforms.unix;
+    mainProgram = "offzip";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/orz/default.nix b/nixpkgs/pkgs/tools/compression/orz/default.nix
new file mode 100644
index 000000000000..b760b0132ef7
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/orz/default.nix
@@ -0,0 +1,40 @@
+{ lib
+, rustPlatform
+, fetchFromGitHub
+, rust-cbindgen
+}:
+
+rustPlatform.buildRustPackage rec {
+  pname = "orz";
+  version = "1.6.2";
+
+  src = fetchFromGitHub {
+    owner = "richox";
+    repo = "orz";
+    rev = "v${version}";
+    hash = "sha256-Yro+iXlg18Pj/AkU4IjvgA88xctK65yStfTilz+IRs0=";
+  };
+
+  cargoHash = "sha256-aUsRbIajBP6esjW7Wj7mqIkbYUCbZ2GgxjRXMPTnHYg=";
+
+  outputs = [ "out" "dev" "lib" ];
+
+  nativeBuildInputs = [
+    rust-cbindgen
+  ];
+
+  postInstall = ''
+    cbindgen -o $dev/include/orz.h
+
+    mkdir -p $lib
+    mv $out/lib "$lib"
+  '';
+
+  meta = with lib; {
+    description = "A high performance, general purpose data compressor written in rust";
+    homepage = "https://github.com/richox/orz";
+    license = licenses.mit;
+    maintainers = with maintainers; [ figsoda ];
+    mainProgram = "orz";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/ouch/default.nix b/nixpkgs/pkgs/tools/compression/ouch/default.nix
new file mode 100644
index 000000000000..07a5302b5a17
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/ouch/default.nix
@@ -0,0 +1,54 @@
+{ lib
+, rustPlatform
+, fetchFromGitHub
+, installShellFiles
+, pkg-config
+, bzip2
+, xz
+, zlib
+, zstd
+, stdenv
+}:
+
+rustPlatform.buildRustPackage rec {
+  pname = "ouch";
+  version = "0.5.1";
+
+  src = fetchFromGitHub {
+    owner = "ouch-org";
+    repo = "ouch";
+    rev = version;
+    hash = "sha256-WO1fetu39fcLGcrbzFh+toHpnyxWuDVHtmjuH203hzQ=";
+  };
+
+  cargoHash = "sha256-OdAu7fStTJCF1JGJG9TRE1Qosy6yjKsWq01MYpbXZcg=";
+
+  nativeBuildInputs = [ installShellFiles pkg-config ];
+
+  buildInputs = [ bzip2 xz zlib zstd ];
+
+  buildFeatures = [ "zstd/pkg-config" ];
+
+  preCheck = ''
+    substituteInPlace tests/ui.rs \
+      --replace 'format!(r"/private{path}")' 'path.to_string()'
+  '';
+
+  postInstall = ''
+    installManPage artifacts/*.1
+    installShellCompletion artifacts/ouch.{bash,fish} --zsh artifacts/_ouch
+  '';
+
+  env = { OUCH_ARTIFACTS_FOLDER = "artifacts"; } //
+    # Work around https://github.com/NixOS/nixpkgs/issues/166205.
+    lib.optionalAttrs stdenv.cc.isClang { NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}"; };
+
+  meta = with lib; {
+    description = "A command-line utility for easily compressing and decompressing files and directories";
+    homepage = "https://github.com/ouch-org/ouch";
+    changelog = "https://github.com/ouch-org/ouch/blob/${version}/CHANGELOG.md";
+    license = licenses.mit;
+    maintainers = with maintainers; [ figsoda psibi ];
+    mainProgram = "ouch";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/pbzip2/default.nix b/nixpkgs/pkgs/tools/compression/pbzip2/default.nix
new file mode 100644
index 000000000000..81144fb14b19
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/pbzip2/default.nix
@@ -0,0 +1,30 @@
+{ lib, stdenv, fetchurl, bzip2 }:
+
+let major = "1.1";
+    version = "${major}.13";
+in
+stdenv.mkDerivation rec {
+  pname = "pbzip2";
+  inherit version;
+
+  src = fetchurl {
+    url = "https://launchpad.net/pbzip2/${major}/${version}/+download/${pname}-${version}.tar.gz";
+    sha256 = "1rnvgcdixjzbrmcr1nv9b6ccrjfrhryaj7jwz28yxxv6lam3xlcg";
+  };
+
+  buildInputs = [ bzip2 ];
+
+  preBuild = "substituteInPlace Makefile --replace g++ c++";
+
+  installFlags = [ "PREFIX=$(out)" ];
+
+  env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-Wno-error=reserved-user-defined-literal";
+
+  meta = with lib; {
+    homepage = "http://compression.ca/pbzip2/";
+    description = "A parallel implementation of bzip2 for multi-core machines";
+    license = licenses.bsd2;
+    maintainers = with maintainers; [viric];
+    platforms = platforms.unix;
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/pbzx/default.nix b/nixpkgs/pkgs/tools/compression/pbzx/default.nix
new file mode 100644
index 000000000000..44555cd6ddbc
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/pbzx/default.nix
@@ -0,0 +1,27 @@
+{stdenv, lib, fetchFromGitHub, xz, xar}:
+
+stdenv.mkDerivation rec {
+  pname = "pbzx";
+  version = "1.0.2";
+  src = fetchFromGitHub {
+    owner = "NiklasRosenstein";
+    repo = "pbzx";
+    rev = "v${version}";
+    sha256 = "0bwd7wmnhpz1n5p39mh6asfyccj4cm06hwigslcwbb3pdwmvxc90";
+  };
+  buildInputs = [ xz xar ];
+  buildPhase = ''
+    ${stdenv.cc.targetPrefix}cc pbzx.c -llzma -lxar -o pbzx
+  '';
+  installPhase = ''
+    mkdir -p $out/bin
+    cp pbzx $out/bin
+  '';
+  meta = with lib; {
+    description = "Stream parser of Apple's pbzx compression format";
+    platforms = platforms.unix;
+    license = licenses.gpl3;
+    maintainers = [ maintainers.matthewbauer ];
+    mainProgram = "pbzx";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/pigz/default.nix b/nixpkgs/pkgs/tools/compression/pigz/default.nix
new file mode 100644
index 000000000000..79363eecade3
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/pigz/default.nix
@@ -0,0 +1,41 @@
+{ lib, stdenv, fetchFromGitHub, zlib, util-linux }:
+
+stdenv.mkDerivation rec {
+  pname = "pigz";
+  version = "2.8";
+
+  src = fetchFromGitHub {
+      owner = "madler";
+      repo = pname;
+      rev = "refs/tags/v${version}";
+      sha256 = "sha256-PzdxyO4mCg2jE/oBk1MH+NUdWM95wIIIbncBg71BkmQ=";
+  };
+
+  enableParallelBuilding = true;
+
+  buildInputs = [ zlib ] ++ lib.optional stdenv.isLinux util-linux;
+
+  makeFlags = [ "CC=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" ];
+
+  doCheck = stdenv.isLinux;
+  checkTarget = "tests";
+  installPhase = ''
+    runHook preInstall
+
+    install -Dm755 pigz "$out/bin/pigz"
+    ln -s pigz "$out/bin/unpigz"
+    install -Dm755 pigz.1 "$out/share/man/man1/pigz.1"
+    ln -s pigz.1 "$out/share/man/man1/unpigz.1"
+    install -Dm755 pigz.pdf "$out/share/doc/pigz/pigz.pdf"
+
+    runHook postInstall
+  '';
+
+  meta = with lib; {
+    homepage = "https://www.zlib.net/pigz/";
+    description = "A parallel implementation of gzip for multi-core machines";
+    maintainers = with maintainers; [ ];
+    license = licenses.zlib;
+    platforms = platforms.unix;
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/pixz/default.nix b/nixpkgs/pkgs/tools/compression/pixz/default.nix
new file mode 100644
index 000000000000..9eb1d6539cdf
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/pixz/default.nix
@@ -0,0 +1,52 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, autoconf
+, automake
+, libtool
+, pkg-config
+, asciidoc
+, libxslt
+, libxml2
+, docbook_xml_dtd_45
+, docbook_xsl
+, libarchive
+, xz
+}:
+
+stdenv.mkDerivation rec {
+  pname = "pixz";
+  version = "1.0.7";
+
+  nativeBuildInputs = [ pkg-config autoconf automake ];
+  buildInputs = [
+    libtool
+    asciidoc
+    libxslt
+    libxml2
+    docbook_xml_dtd_45
+    docbook_xsl
+    libarchive
+    xz
+  ];
+  preBuild = ''
+    echo "XML_CATALOG_FILES='$XML_CATALOG_FILES'"
+  '';
+  src = fetchFromGitHub {
+    owner = "vasi";
+    repo = pname;
+    rev = "v${version}";
+    sha256 = "163axxs22w7pghr786hda22mnlpvmi50hzhfr9axwyyjl9n41qs2";
+  };
+  preConfigure = ''
+    ./autogen.sh
+  '';
+
+  meta = with lib; {
+    description = "A parallel compressor/decompressor for xz format";
+    license = licenses.bsd2;
+    maintainers = [ maintainers.raskin ];
+    platforms = platforms.unix;
+    mainProgram = "pixz";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/pxz/default.nix b/nixpkgs/pkgs/tools/compression/pxz/default.nix
new file mode 100644
index 000000000000..f61e80cbc065
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/pxz/default.nix
@@ -0,0 +1,56 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, testers
+, pxz
+, xz
+}:
+
+stdenv.mkDerivation rec {
+  pname = "pxz";
+  version = "4.999.9beta";
+
+  src = fetchFromGitHub {
+    owner = "jnovy";
+    repo = "pxz";
+    rev = "124382a6d0832b13b7c091f72264f8f3f463070a";
+    hash = "sha256-NYhPujm5A0j810IKUZEHru/oLXCW7xZf5FjjKAbatZY=";
+  };
+
+  patches = [ ./flush-stdout-help-version.patch ];
+
+  postPatch = ''
+    substituteInPlace Makefile \
+      --replace '`date +%Y%m%d`' '19700101'
+
+    substituteInPlace pxz.c \
+      --replace 'XZ_BINARY "xz"' 'XZ_BINARY "${lib.getBin xz}/bin/xz"'
+  '';
+
+  buildInputs = [ xz ];
+
+  makeFlags = [
+    "BINDIR=${placeholder "out"}/bin"
+    "MANDIR=${placeholder "out"}/share/man"
+  ];
+
+  passthru.tests.version = testers.testVersion {
+    package = pxz;
+  };
+
+  meta = with lib; {
+    homepage = "https://jnovy.fedorapeople.org/pxz/";
+    license = licenses.gpl2Plus;
+    maintainers = with maintainers; [ pashev ];
+    description = "compression utility that runs LZMA compression of different parts on multiple cores simultaneously";
+    longDescription = ''
+      Parallel XZ is a compression utility that takes advantage of
+      running LZMA compression of different parts of an input file on multiple
+      cores and processors simultaneously. Its primary goal is to utilize all
+      resources to speed up compression time with minimal possible influence
+      on compression ratio
+    '';
+    mainProgram = "pxz";
+    platforms = with platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/pxz/flush-stdout-help-version.patch b/nixpkgs/pkgs/tools/compression/pxz/flush-stdout-help-version.patch
new file mode 100644
index 000000000000..797cdbeb1f8f
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/pxz/flush-stdout-help-version.patch
@@ -0,0 +1,32 @@
+From bba741ccd0f0a65cd9bfdd81504ebe5840fd37ad Mon Sep 17 00:00:00 2001
+From: Will Dietz <w@wdtz.org>
+Date: Tue, 22 Mar 2022 08:01:10 -0500
+Subject: [PATCH] pxz: flush stdout before exec'ing xz, ensure our messages are
+ printed
+
+Without this, they're presently dropped on my system when pxz
+is piped to something, as in `pxz --help|less` or `pxz --version|cat`.
+---
+ pxz.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/pxz.c b/pxz.c
+index 4240b6e..3b53cfa 100644
+--- a/pxz.c
++++ b/pxz.c
+@@ -184,10 +184,12 @@ void parse_args( int argc, char **argv, char **envp ) {
+ 					"  -D, --context-size  per-thread compression context size as a multiple\n"
+ 					"                      of dictionary size. Default is 3.\n\n"
+ 					"Usage and other options are same as in XZ:\n\n");
++				fflush(stdout);
+ 				run_xz(argv, envp);
+ 				break;
+ 			case 'V':
+ 				printf("Parallel PXZ "PXZ_VERSION" (build "PXZ_BUILD_DATE")\n");
++				fflush(stdout);
+ 				run_xz(argv, envp);
+ 				break;
+ 			case 'g':
+-- 
+2.35.1
+
diff --git a/nixpkgs/pkgs/tools/compression/rzip/default.nix b/nixpkgs/pkgs/tools/compression/rzip/default.nix
new file mode 100644
index 000000000000..3d744dfa35fd
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/rzip/default.nix
@@ -0,0 +1,31 @@
+{ lib, stdenv, fetchurl, fetchpatch, bzip2 }:
+
+stdenv.mkDerivation rec {
+  pname = "rzip";
+  version = "2.1";
+
+  src = fetchurl {
+    url = "mirror://samba/rzip/rzip-${version}.tar.gz";
+    sha256 = "4bb96f4d58ccf16749ed3f836957ce97dbcff3e3ee5fd50266229a48f89815b7";
+  };
+  buildInputs = [ bzip2 ];
+
+  patches = [
+    (fetchpatch {
+      name = "CVE-2017-8364-fill-buffer.patch";
+      url = "https://sources.debian.net/data/main/r/rzip/2.1-4.1/debian/patches/80-CVE-2017-8364-fill-buffer.patch";
+      sha256 = "0jcjlx9ksdvxvjyxmyzscx9ar9992iy5icw0sc3n0p09qi4d6x1r";
+    })
+  ];
+
+  env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-Wno-error=implicit-int";
+
+  meta = with lib; {
+    homepage = "https://rzip.samba.org/";
+    description = "Compression program";
+    maintainers = with maintainers; [ ];
+    license = licenses.gpl2Plus;
+    platforms = platforms.unix;
+    mainProgram = "rzip";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/unzrip/default.nix b/nixpkgs/pkgs/tools/compression/unzrip/default.nix
new file mode 100644
index 000000000000..2e92fadd39a9
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/unzrip/default.nix
@@ -0,0 +1,36 @@
+{ lib
+, rustPlatform
+, fetchFromGitHub
+, pkg-config
+, zstd
+}:
+
+rustPlatform.buildRustPackage rec {
+  pname = "unzrip";
+  version = "unstable-2023-04-16";
+
+  src = fetchFromGitHub {
+    owner = "quininer";
+    repo = "unzrip";
+    rev = "14ba4b4c9ff9c80444ecef762d665acaa5aecfce";
+    hash = "sha256-QYu4PXWQGagj7r8lLs0IngIXzt6B8uq2qonycaGDg6g=";
+  };
+
+  cargoHash = "sha256-9CjKSdd+E2frI8VvdOawYQ3u+KF22xw9kBpnAufRUG0=";
+
+  nativeBuildInputs = [
+    pkg-config
+  ];
+
+  buildInputs = [
+    zstd
+  ];
+
+  meta = with lib; {
+    description = "Unzip implementation, support for parallel decompression, automatic detection encoding";
+    homepage = "https://github.com/quininer/unzrip";
+    license = licenses.mit;
+    maintainers = with maintainers; [ figsoda ];
+    mainProgram = "unzrip";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/upx/default.nix b/nixpkgs/pkgs/tools/compression/upx/default.nix
new file mode 100644
index 000000000000..c9a516705b0e
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/upx/default.nix
@@ -0,0 +1,35 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, cmake
+, nix-update-script
+, testers
+}:
+
+stdenv.mkDerivation (finalAttrs: {
+  pname = "upx";
+  version = "4.2.2";
+  src = fetchFromGitHub {
+    owner = "upx";
+    repo = "upx";
+    rev = "v${finalAttrs.version}";
+    fetchSubmodules = true;
+    hash = "sha256-0x7SUW+rB5HNRoRkCQIwfOIMpu+kOifxA7Z3SUlY/ME=";
+  };
+
+  nativeBuildInputs = [ cmake ];
+
+  passthru = {
+    updateScript = nix-update-script { };
+    tests.version = testers.testVersion { package = finalAttrs.finalPackage; };
+  };
+
+  meta = with lib; {
+    homepage = "https://upx.github.io/";
+    description = "The Ultimate Packer for eXecutables";
+    changelog = "https://github.com/upx/upx/blob/${finalAttrs.src.rev}/NEWS";
+    license = licenses.gpl2Plus;
+    platforms = platforms.unix;
+    mainProgram = "upx";
+  };
+})
diff --git a/nixpkgs/pkgs/tools/compression/xar/0001-Add-useless-descriptions-to-AC_DEFINE.patch b/nixpkgs/pkgs/tools/compression/xar/0001-Add-useless-descriptions-to-AC_DEFINE.patch
new file mode 100644
index 000000000000..a605d2db1708
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/xar/0001-Add-useless-descriptions-to-AC_DEFINE.patch
@@ -0,0 +1,95 @@
+From a14be07c0aae3bf6f732d1ca5f625ba375702121 Mon Sep 17 00:00:00 2001
+From: Andrew Childs <andrew.childs@bibo.com.ph>
+Date: Sun, 15 Nov 2020 19:12:33 +0900
+Subject: [PATCH 1/2] Add useless descriptions to AC_DEFINE
+
+Removes autoheader warnings.
+---
+ configure.ac | 42 +++++++++++++++++++++---------------------
+ 1 file changed, 21 insertions(+), 21 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index 812b5ff..358ab89 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -210,48 +210,48 @@ AC_CHECK_MEMBERS([struct stat.st_flags])
+ 
+ AC_CHECK_SIZEOF(uid_t)
+ if test $ac_cv_sizeof_uid_t = "4"; then
+-AC_DEFINE(UID_STRING, RId32)
+-AC_DEFINE(UID_CAST, (uint32_t))
++AC_DEFINE([UID_STRING], RId32, [UID_STRING])
++AC_DEFINE([UID_CAST], (uint32_t), [UID_CAST])
+ elif test $ac_cv_sizeof_uid_t = "8"; then
+-AC_DEFINE(UID_STRING, PRId64)
+-AC_DEFINE(UID_CAST, (uint64_t))
++AC_DEFINE([UID_STRING], PRId64, [UID_STRING])
++AC_DEFINE([UID_CAST], (uint64_t), [UID_CAST])
+ else
+ AC_ERROR(can not detect the size of your system's uid_t type)
+ fi
+ 
+ AC_CHECK_SIZEOF(gid_t)
+ if test $ac_cv_sizeof_gid_t = "4"; then
+-AC_DEFINE(GID_STRING, PRId32)
+-AC_DEFINE(GID_CAST, (uint32_t))
++AC_DEFINE([GID_STRING], PRId32, [GID_STRING])
++AC_DEFINE([GID_CAST], (uint32_t), [GID_CAST])
+ elif test $ac_cv_sizeof_gid_t = "8"; then
+-AC_DEFINE(GID_STRING, PRId64)
+-AC_DEFINE(GID_CAST, (uint64_t))
++AC_DEFINE([GID_STRING], PRId64, [GID_STRING])
++AC_DEFINE([GID_CAST], (uint64_t), [GID_CAST])
+ else
+ AC_ERROR(can not detect the size of your system's gid_t type)
+ fi
+ 
+ AC_CHECK_SIZEOF(ino_t)
+ if test $ac_cv_sizeof_ino_t = "4"; then
+-AC_DEFINE(INO_STRING, PRId32)
+-AC_DEFINE(INO_HEXSTRING, PRIx32)
+-AC_DEFINE(INO_CAST, (uint32_t))
++AC_DEFINE([INO_STRING], PRId32, [INO_STRING])
++AC_DEFINE([INO_HEXSTRING], PRIx32, [INO_HEXSTRING])
++AC_DEFINE([INO_CAST], (uint32_t), [INO_CAST])
+ elif test $ac_cv_sizeof_ino_t = "8"; then
+-AC_DEFINE(INO_STRING, PRId64)
+-AC_DEFINE(INO_HEXSTRING, PRIx64)
+-AC_DEFINE(INO_CAST, (uint64_t))
++AC_DEFINE([INO_STRING], PRId64, [INO_STRING])
++AC_DEFINE([INO_HEXSTRING], PRIx64, [INO_HEXSTRING])
++AC_DEFINE([INO_CAST], (uint64_t), [INO_CAST])
+ else
+ AC_ERROR(can not detect the size of your system's ino_t type)
+ fi
+ 
+ AC_CHECK_SIZEOF(dev_t)
+ if test $ac_cv_sizeof_dev_t = "4"; then
+-AC_DEFINE(DEV_STRING, PRId32)
+-AC_DEFINE(DEV_HEXSTRING, PRIx32)
+-AC_DEFINE(DEV_CAST, (uint32_t))
++AC_DEFINE([DEV_STRING], PRId32, [DEV_STRING])
++AC_DEFINE([DEV_HEXSTRING], PRIx32, [DEV_HEXSTRING])
++AC_DEFINE([DEV_CAST], (uint32_t), [DEV_CAST])
+ elif test $ac_cv_sizeof_dev_t = "8"; then
+-AC_DEFINE(DEV_STRING, PRId64)
+-AC_DEFINE(DEV_HEXSTRING, PRIx64)
+-AC_DEFINE(DEV_CAST, (uint64_t))
++AC_DEFINE([DEV_STRING], PRId64, [DEV_STRING])
++AC_DEFINE([DEV_HEXSTRING], PRIx64, [DEV_HEXSTRING])
++AC_DEFINE([DEV_CAST], (uint64_t), [DEV_CAST])
+ else
+ AC_ERROR(can not detect the size of your system's dev_t type)
+ fi
+@@ -261,7 +261,7 @@ AC_CHECK_LIB(acl, acl_get_file)
+ dnl Check for paths
+ AC_PREFIX_DEFAULT(/usr/local)
+ 
+-AC_CHECK_FUNC([asprintf], AC_DEFINE([HAVE_ASPRINTF]))
++AC_CHECK_FUNC([asprintf], AC_DEFINE([HAVE_ASPRINTF], [], [HAVE_ASPRINTF]))
+ 
+ dnl 
+ dnl Configure libxml2.
+-- 
+2.28.0
+
diff --git a/nixpkgs/pkgs/tools/compression/xar/0002-Use-pkg-config-for-libxml2.patch b/nixpkgs/pkgs/tools/compression/xar/0002-Use-pkg-config-for-libxml2.patch
new file mode 100644
index 000000000000..d71ad4b753c1
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/xar/0002-Use-pkg-config-for-libxml2.patch
@@ -0,0 +1,89 @@
+From 276833851657c85651c053ee16b8e1a8dc768a50 Mon Sep 17 00:00:00 2001
+From: Andrew Childs <andrew.childs@bibo.com.ph>
+Date: Sun, 15 Nov 2020 19:12:56 +0900
+Subject: [PATCH 2/2] Use pkg-config for libxml2
+
+---
+ configure.ac | 66 +++++++++-------------------------------------------
+ 1 file changed, 11 insertions(+), 55 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index 358ab89..984a694 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -268,61 +268,17 @@ dnl Configure libxml2.
+ dnl 
+ LIBXML2_VERSION_MIN=2.6.11
+ 
+-have_libxml2="1"
+-
+-AC_ARG_WITH([xml2-config], [  --with-xml2-config      libxml2 config program],
+-if test "x${with_xml2_config}" = "xno" ; then
+-  XML2_CONFIG=
+-else
+-  XML2_CONFIG="${with_xml2_config}"
+-fi
+-,
+-  XML2_CONFIG=
+-)
+-if test "x${XML2_CONFIG}" != "x" ; then
+-   if test ! -x "${XML2_CONFIG}" ; then
+-     AC_MSG_ERROR([Unusable or missing xml2-config: ${XML2_CONFIG}])
+-   fi
+-else
+-  AC_PATH_PROG([XML2_CONFIG], [xml2-config], , [${PATH}])
+-  if test "x${XML2_CONFIG}" = "x" ; then
+-    AC_MSG_ERROR([Cannot configure without xml2-config])
+-  fi
+-fi
+-
+-dnl Make sure the version of libxml2 found is sufficient.
+-AC_MSG_CHECKING([for libxml >= ${LIBXML2_VERSION_MIN}])
+-LIBXML2_FOUND=`2>&1 ${XML2_CONFIG} --version`
+-LIBXML2_MAJOR=`echo ${LIBXML2_FOUND} | tr . " " | awk '{print $1}'`
+-LIBXML2_MINOR=`echo ${LIBXML2_FOUND} | tr . " " | awk '{print $2}' | tr a-z " " |awk '{print $1}'`
+-LIBXML2_BRANCH=`echo ${LIBXML2_FOUND} | tr . " " | awk '{print $3}' | tr a-z " " |awk '{print $1}'`
+-if test "x${LIBXML2_BRANCH}" = "x" ; then
+-  LIBXML2_BRANCH=0
+-fi
+-LIBXML2_MAJOR_MIN=`echo ${LIBXML2_VERSION_MIN} | tr . " " | awk '{print $1}'`
+-LIBXML2_MINOR_MIN=`echo ${LIBXML2_VERSION_MIN} | tr . " " | awk '{print $2}'`
+-LIBXML2_BRANCH_MIN=`echo ${LIBXML2_VERSION_MIN} | tr . " " | awk '{print $3}'`
+-if test ${LIBXML2_MAJOR} -gt ${LIBXML2_MAJOR_MIN} \
+-     -o ${LIBXML2_MAJOR} -eq ${LIBXML2_MAJOR_MIN} \
+-     -a ${LIBXML2_MINOR} -gt ${LIBXML2_MINOR_MIN} \
+-     -o ${LIBXML2_MAJOR} -eq ${LIBXML2_MAJOR_MIN} \
+-     -a ${LIBXML2_MINOR} -eq ${LIBXML2_MINOR_MIN} \
+-     -a ${LIBXML2_BRANCH} -ge $LIBXML2_BRANCH_MIN ; then
+-  AC_MSG_RESULT([${LIBXML2_MAJOR}.${LIBXML2_MINOR}.${LIBXML2_BRANCH}])
+-  have_libxml2="1"
+-  CPPFLAGS="${CPPFLAGS} `${XML2_CONFIG} --cflags`"
+-  LIBS="${LIBS} `${XML2_CONFIG} --libs`"
+-else
+-  AC_MSG_RESULT([no])
+-  have_libxml2="0"
+-fi
+-if test "x${have_libxml2}" = "x1" ; then
+-  dnl Final sanity check, to make sure that xmlwriter is present.
+-  AC_CHECK_HEADER([libxml/xmlwriter.h], , [have_libxml2="0"])
+-fi
+-if test "x${have_libxml2}" = "x0" ; then
+-  AC_MSG_ERROR([Cannot build without libxml2])
+-fi
++PKG_PROG_PKG_CONFIG
++
++PKG_CHECK_MODULES(LIBXML2_PKGCONFIG, [libxml-2.0 >= ${LIBXML2_VERSION_MIN}],
++  [
++    have_libxml2=1
++    CPPFLAGS="${CPPFLAGS} ${LIBXML2_PKGCONFIG_CFLAGS}"
++    LIBS="${LIBS} ${LIBXML2_PKGCONFIG_LIBS}"
++  ],
++  [
++    have_libxml2=0
++  ])
+ 
+ dnl 
+ dnl Configure libcrypto (part of OpenSSL).
+-- 
+2.28.0
+
diff --git a/nixpkgs/pkgs/tools/compression/xar/default.nix b/nixpkgs/pkgs/tools/compression/xar/default.nix
new file mode 100644
index 000000000000..9c03c41054be
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/xar/default.nix
@@ -0,0 +1,49 @@
+{ lib, stdenv, fetchurl, pkg-config, libxml2, xz, openssl, zlib, bzip2, fts, autoreconfHook }:
+
+stdenv.mkDerivation rec {
+  version = "1.6.1";
+  pname = "xar";
+
+  src = fetchurl {
+    url    = "https://github.com/downloads/mackyle/xar/${pname}-${version}.tar.gz";
+    sha256 = "0ghmsbs6xwg1092v7pjcibmk5wkyifwxw6ygp08gfz25d2chhipf";
+  };
+
+  nativeBuildInputs = [ autoreconfHook pkg-config ];
+  buildInputs = [ libxml2 xz openssl zlib bzip2 fts ];
+
+  patches = [
+    ./0001-Add-useless-descriptions-to-AC_DEFINE.patch
+    ./0002-Use-pkg-config-for-libxml2.patch
+  ];
+
+  postPatch = ''
+    substituteInPlace configure.ac \
+      --replace 'OpenSSL_add_all_ciphers' 'OPENSSL_init_crypto' \
+      --replace 'openssl/evp.h' 'openssl/crypto.h'
+  '';
+
+  configureFlags = lib.optional (fts != null) "LDFLAGS=-lfts";
+
+  meta = {
+    homepage    = "https://mackyle.github.io/xar/";
+    description = "Extensible Archiver";
+
+    longDescription =
+      '' The XAR project aims to provide an easily extensible archive format.
+         Important design decisions include an easily extensible XML table of
+         contents for random access to archived files, storing the toc at the
+         beginning of the archive to allow for efficient handling of streamed
+         archives, the ability to handle files of arbitrarily large sizes, the
+         ability to choose independent encodings for individual files in the
+         archive, the ability to store checksums for individual files in both
+         compressed and uncompressed form, and the ability to query the table
+         of content's rich meta-data.
+      '';
+
+    license     = lib.licenses.bsd3;
+    maintainers = with lib.maintainers; [ copumpkin ];
+    platforms   = lib.platforms.all;
+    mainProgram = "xar";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/xdelta/default.nix b/nixpkgs/pkgs/tools/compression/xdelta/default.nix
new file mode 100644
index 000000000000..27d0141ff75b
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/xdelta/default.nix
@@ -0,0 +1,62 @@
+{ lib, stdenv, fetchFromGitHub, autoreconfHook
+, lzmaSupport ? true, xz ? null
+}:
+
+assert lzmaSupport -> xz != null;
+
+let
+  mkWith = flag: name: if flag
+    then "--with-${name}"
+    else "--without-${name}";
+in stdenv.mkDerivation rec {
+  pname = "xdelta";
+  version = "3.1.0";
+
+  src = fetchFromGitHub {
+    sha256 = "09mmsalc7dwlvgrda56s2k927rpl3a5dzfa88aslkqcjnr790wjy";
+    rev = "v${version}";
+    repo = "xdelta-devel";
+    owner = "jmacd";
+  };
+
+  nativeBuildInputs = [ autoreconfHook ];
+  buildInputs = []
+    ++ lib.optionals lzmaSupport [ xz ];
+
+  postPatch = ''
+    cd xdelta3
+  '';
+
+  configureFlags = [
+    (mkWith lzmaSupport "liblzma")
+  ];
+
+  enableParallelBuilding = true;
+
+  doCheck = true;
+  checkPhase = ''
+    mkdir $PWD/tmp
+    for i in testing/file.h xdelta3-test.h; do
+      substituteInPlace $i --replace /tmp $PWD/tmp
+    done
+    ./xdelta3regtest
+  '';
+
+  installPhase = ''
+    install -D -m755 xdelta3 $out/bin/xdelta3
+    install -D -m644 xdelta3.1 $out/share/man/man1/xdelta3.1
+  '';
+
+  meta = with lib; {
+    description = "Binary differential compression in VCDIFF (RFC 3284) format";
+    longDescription = ''
+      xdelta is a command line program for delta encoding, which generates two
+      file differences. This is similar to diff and patch, but it is targeted
+      for binary files and does not generate human readable output.
+    '';
+    homepage = "http://xdelta.org/";
+    license = licenses.gpl2Plus;
+    mainProgram = "xdelta3";
+    platforms = platforms.unix;
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/xdelta/unstable.nix b/nixpkgs/pkgs/tools/compression/xdelta/unstable.nix
new file mode 100644
index 000000000000..2ac8398dbc2d
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/xdelta/unstable.nix
@@ -0,0 +1,66 @@
+{ lib, stdenv, fetchFromGitHub, autoreconfHook
+, lzmaSupport ? true, xz ? null
+}:
+
+assert lzmaSupport -> xz != null;
+
+let
+  mkWith = flag: name: if flag
+    then "--with-${name}"
+    else "--without-${name}";
+in stdenv.mkDerivation rec {
+  pname = "xdelta";
+  version = "3.1.0";
+
+  src = fetchFromGitHub {
+    sha256 = "09mmsalc7dwlvgrda56s2k927rpl3a5dzfa88aslkqcjnr790wjy";
+    rev = "v${version}";
+    repo = "xdelta-devel";
+    owner = "jmacd";
+  };
+
+  nativeBuildInputs = [ autoreconfHook ];
+  buildInputs = []
+    ++ lib.optionals lzmaSupport [ xz ];
+
+  postPatch = ''
+    cd xdelta3
+
+    substituteInPlace Makefile.am --replace \
+      "common_CFLAGS =" \
+      "common_CFLAGS = -DXD3_USE_LARGESIZET=1"
+  '';
+
+  configureFlags = [
+    (mkWith lzmaSupport "liblzma")
+  ];
+
+  enableParallelBuilding = true;
+
+  doCheck = true;
+  checkPhase = ''
+    mkdir $PWD/tmp
+    for i in testing/file.h xdelta3-test.h; do
+      substituteInPlace $i --replace /tmp $PWD/tmp
+    done
+    ./xdelta3regtest
+  '';
+
+  installPhase = ''
+    install -D -m755 xdelta3 $out/bin/xdelta3
+    install -D -m644 xdelta3.1 $out/share/man/man1/xdelta3.1
+  '';
+
+  meta = with lib; {
+    description = "Binary differential compression in VCDIFF (RFC 3284) format";
+    longDescription = ''
+      xdelta is a command line program for delta encoding, which generates two
+      file differences. This is similar to diff and patch, but it is targeted
+      for binary files and does not generate human readable output.
+    '';
+    homepage = "http://xdelta.org/";
+    license = licenses.gpl2Plus;
+    mainProgram = "xdelta3";
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/xz/default.nix b/nixpkgs/pkgs/tools/compression/xz/default.nix
new file mode 100644
index 000000000000..e02be74b60d3
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/xz/default.nix
@@ -0,0 +1,81 @@
+{ lib, stdenv, fetchurl
+, enableStatic ? stdenv.hostPlatform.isStatic
+, writeScript
+, testers
+}:
+
+# Note: this package is used for bootstrapping fetchurl, and thus
+# cannot use fetchpatch! All mutable patches (generated by GitHub or
+# cgit) that are needed here should be included directly in Nixpkgs as
+# files.
+
+stdenv.mkDerivation (finalAttrs: {
+  pname = "xz";
+  version = "5.4.6";
+
+  src = fetchurl {
+    url = with finalAttrs; "https://github.com/tukaani-project/xz/releases/download/v${version}/xz-${version}.tar.bz2";
+    sha256 = "sha256-kThRsnTo4dMXgeyUnxwj6NvPDs9uc6JDbcIXad0+b0k=";
+  };
+
+  strictDeps = true;
+  outputs = [ "bin" "dev" "out" "man" "doc" ];
+
+  configureFlags = lib.optional enableStatic "--disable-shared";
+
+  enableParallelBuilding = true;
+  doCheck = true;
+
+  preCheck = ''
+    # Tests have a /bin/sh dependency...
+    patchShebangs tests
+  '';
+
+  # In stdenv-linux, prevent a dependency on bootstrap-tools.
+  preConfigure = "CONFIG_SHELL=/bin/sh";
+
+  postInstall = "rm -rf $out/share/doc";
+
+  passthru = {
+    updateScript = writeScript "update-xz" ''
+      #!/usr/bin/env nix-shell
+      #!nix-shell -i bash -p curl pcre common-updater-scripts
+
+      set -eu -o pipefail
+
+      # Expect the text in format of '>xz-5.2.6.tar.bz2</a>'
+      # We pick first match where a stable release goes first.
+      new_version="$(curl -s https://tukaani.org/xz/ |
+          pcregrep -o1 '>xz-([0-9.]+)[.]tar[.]bz2</a>' |
+          head -n1)"
+      update-source-version ${finalAttrs.pname} "$new_version"
+    '';
+    tests.pkg-config = testers.hasPkgConfigModules {
+      package = finalAttrs.finalPackage;
+    };
+  };
+
+  meta = with lib; {
+    homepage = "https://tukaani.org/xz/";
+    description = "A general-purpose data compression software, successor of LZMA";
+
+    longDescription =
+      '' XZ Utils is free general-purpose data compression software with high
+         compression ratio.  XZ Utils were written for POSIX-like systems,
+         but also work on some not-so-POSIX systems.  XZ Utils are the
+         successor to LZMA Utils.
+
+         The core of the XZ Utils compression code is based on LZMA SDK, but
+         it has been modified quite a lot to be suitable for XZ Utils.  The
+         primary compression algorithm is currently LZMA2, which is used
+         inside the .xz container format.  With typical files, XZ Utils
+         create 30 % smaller output than gzip and 15 % smaller output than
+         bzip2.
+      '';
+
+    license = with licenses; [ gpl2Plus lgpl21Plus ];
+    maintainers = with maintainers; [ sander ];
+    platforms = platforms.all;
+    pkgConfigModules = [ "liblzma" ];
+  };
+})
diff --git a/nixpkgs/pkgs/tools/compression/zdelta/default.nix b/nixpkgs/pkgs/tools/compression/zdelta/default.nix
new file mode 100644
index 000000000000..b30a43f33c13
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/zdelta/default.nix
@@ -0,0 +1,24 @@
+{ lib, stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  pname = "zdelta";
+  version = "2.1";
+
+  src = fetchurl {
+    url = "https://web.archive.org/web/20160316212948/http://cis.poly.edu/zdelta/downloads/zdelta-2.1.tar.gz";
+    sha256 = "sha256-WiQKWxJkINIwRBcdiuVLMDiupQ8gOsiXOEZvHDa5iFg=";
+  };
+
+  makeFlags = [ "CC=${stdenv.cc.targetPrefix}cc" ];
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp -p zdc zdu $out/bin
+  '';
+
+  meta = with lib; {
+    homepage = "https://web.archive.org/web/20160316212948/http://cis.poly.edu/zdelta/";
+    platforms = platforms.all;
+    license = licenses.zlib;
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/zfp/default.nix b/nixpkgs/pkgs/tools/compression/zfp/default.nix
new file mode 100644
index 000000000000..8df75d48eb56
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/zfp/default.nix
@@ -0,0 +1,57 @@
+{ cmake, cudatoolkit, fetchFromGitHub, gfortran, lib, llvmPackages, python3Packages, stdenv
+, config
+, enableCfp ? true
+, enableCuda ? config.cudaSupport
+, enableFortran ? builtins.elem stdenv.hostPlatform.system gfortran.meta.platforms
+, enableOpenMP ? true
+, enablePython ? true
+, enableUtilities ? true }:
+
+stdenv.mkDerivation rec {
+  pname = "zfp";
+  version = "1.0.1";
+
+  src = fetchFromGitHub {
+    owner = "LLNL";
+    repo = "zfp";
+    rev = version;
+    sha256 = "sha256-iZxA4lIviZQgaeHj6tEQzEFSKocfgpUyf4WvUykb9qk=";
+  };
+
+  nativeBuildInputs = [ cmake ];
+
+  buildInputs = lib.optional enableCuda cudatoolkit
+    ++ lib.optional enableFortran gfortran
+    ++ lib.optional enableOpenMP llvmPackages.openmp
+    ++ lib.optionals enablePython (with python3Packages; [ cython numpy python ]);
+
+  # compile CUDA code for all extant GPUs so the binary will work with any GPU
+  # and driver combination. to be ultimately solved upstream:
+  # https://github.com/LLNL/zfp/issues/178
+  # NB: not in cmakeFlags due to https://github.com/NixOS/nixpkgs/issues/114044
+  preConfigure = lib.optionalString enableCuda ''
+    cmakeFlagsArray+=(
+      "-DCMAKE_CUDA_FLAGS=-gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_61,code=sm_61 -gencode=arch=compute_70,code=sm_70 -gencode=arch=compute_75,code=sm_75 -gencode=arch=compute_80,code=sm_80 -gencode=arch=compute_86,code=sm_86 -gencode=arch=compute_87,code=sm_87 -gencode=arch=compute_86,code=compute_86"
+    )
+  '';
+
+  cmakeFlags = [
+  ] ++ lib.optional enableCfp "-DBUILD_CFP=ON"
+    ++ lib.optional enableCuda "-DZFP_WITH_CUDA=ON"
+    ++ lib.optional enableFortran "-DBUILD_ZFORP=ON"
+    ++ lib.optional enableOpenMP "-DZFP_WITH_OPENMP=ON"
+    ++ lib.optional enablePython "-DBUILD_ZFPY=ON"
+    ++ ([ "-DBUILD_UTILITIES=${if enableUtilities then "ON" else "OFF"}" ]);
+
+  doCheck = true;
+
+  meta = with lib; {
+    homepage = "https://computing.llnl.gov/projects/zfp";
+    description = "Library for random-access compression of floating-point arrays";
+    license = licenses.bsd3;
+    maintainers = [ maintainers.spease ];
+    # 64-bit only
+    platforms = platforms.aarch64 ++ platforms.x86_64;
+    mainProgram = "zfp";
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/zopfli/default.nix b/nixpkgs/pkgs/tools/compression/zopfli/default.nix
new file mode 100644
index 000000000000..2c844cffc21b
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/zopfli/default.nix
@@ -0,0 +1,39 @@
+{ lib, stdenv, fetchFromGitHub, cmake }:
+
+stdenv.mkDerivation rec {
+  pname = "zopfli";
+  version = "1.0.3";
+  outputs = [ "out" "lib" "dev" ];
+
+  src = fetchFromGitHub {
+    owner = "google";
+    repo = "zopfli";
+    rev = "${pname}-${version}";
+    name = "${pname}-${version}-src";
+    sha256 = "0dr8n4j5nj2h9n208jns56wglw59gg4qm3s7c6y3hs75d0nnkhm4";
+  };
+
+  nativeBuildInputs = [ cmake ];
+
+  cmakeFlags = [ "-DBUILD_SHARED_LIBS=ON" "-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON" ];
+
+  postInstall = ''
+    install -Dm444 -t $out/share/doc/zopfli ../README*
+    cp $src/src/zopfli/*.h $dev/include/
+  '';
+
+  meta = with lib; {
+    inherit (src.meta) homepage;
+    description = "Very good, but slow, deflate or zlib compression";
+    longDescription = ''
+      Zopfli Compression Algorithm is a compression library programmed
+      in C to perform very good, but slow, deflate or zlib compression.
+
+      This library can only compress, not decompress. Existing zlib or
+      deflate libraries can decompress the data.
+    '';
+    platforms = platforms.unix;
+    license = licenses.asl20;
+    maintainers = with maintainers; [ bobvanderlinden edef ];
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/zstd/default.nix b/nixpkgs/pkgs/tools/compression/zstd/default.nix
new file mode 100644
index 000000000000..4ba37c1502f6
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/zstd/default.nix
@@ -0,0 +1,129 @@
+{ lib, stdenv, fetchFromGitHub, cmake, bash, gnugrep
+, fixDarwinDylibNames
+, file
+, legacySupport ? false
+, static ? stdenv.hostPlatform.isStatic # generates static libraries *only*
+, enableStatic ? static
+# these need to be ran on the host, thus disable when cross-compiling
+, buildContrib ? stdenv.hostPlatform == stdenv.buildPlatform
+, doCheck ? stdenv.hostPlatform == stdenv.buildPlatform
+, nix-update-script
+
+# for passthru.tests
+, libarchive
+, rocksdb
+, arrow-cpp
+, libzip
+, curl
+, python3Packages
+, haskellPackages
+}:
+
+stdenv.mkDerivation rec {
+  pname = "zstd";
+  version = "1.5.5";
+
+  src = fetchFromGitHub {
+    owner = "facebook";
+    repo = "zstd";
+    rev = "v${version}";
+    sha256 = "sha256-tHHHIsQU7vJySrVhJuMKUSq11MzkmC+Pcsj00uFJdnQ=";
+  };
+
+  nativeBuildInputs = [ cmake ]
+   ++ lib.optional stdenv.isDarwin fixDarwinDylibNames;
+  buildInputs = lib.optional stdenv.hostPlatform.isUnix bash;
+
+  patches = [
+    # This patches makes sure we do not attempt to use the MD5 implementation
+    # of the host platform when running the tests
+    ./playtests-darwin.patch
+  ];
+
+  postPatch = lib.optionalString (!static) ''
+    substituteInPlace build/cmake/CMakeLists.txt \
+      --replace 'message(SEND_ERROR "You need to build static library to build tests")' ""
+    substituteInPlace build/cmake/tests/CMakeLists.txt \
+      --replace 'libzstd_static' 'libzstd_shared'
+    sed -i \
+      "1aexport ${lib.optionalString stdenv.isDarwin "DY"}LD_LIBRARY_PATH=$PWD/build_/lib" \
+      tests/playTests.sh
+  '';
+
+  cmakeFlags = lib.attrsets.mapAttrsToList
+    (name: value: "-DZSTD_${name}:BOOL=${if value then "ON" else "OFF"}") {
+      BUILD_SHARED = !static;
+      BUILD_STATIC = enableStatic;
+      BUILD_CONTRIB = buildContrib;
+      PROGRAMS_LINK_SHARED = !static;
+      LEGACY_SUPPORT = legacySupport;
+      BUILD_TESTS = doCheck;
+    };
+
+  cmakeDir = "../build/cmake";
+  dontUseCmakeBuildDir = true;
+  preConfigure = ''
+    mkdir -p build_ && cd $_
+  '';
+
+  nativeCheckInputs = [ file ];
+  inherit doCheck;
+  checkPhase = ''
+    runHook preCheck
+    # Patch shebangs for playTests
+    patchShebangs ../programs/zstdgrep
+    ctest -R playTests # The only relatively fast test.
+    runHook postCheck
+  '';
+
+  preInstall = ''
+    mkdir -p $bin/bin
+    substituteInPlace ../programs/zstdgrep \
+      --replace ":-grep" ":-${gnugrep}/bin/grep" \
+      --replace ":-zstdcat" ":-$bin/bin/zstdcat"
+
+    substituteInPlace ../programs/zstdless \
+      --replace "zstdcat" "$bin/bin/zstdcat"
+  '' + lib.optionalString buildContrib (
+    ''
+      cp contrib/pzstd/pzstd $bin/bin/pzstd
+    '' + lib.optionalString stdenv.isDarwin ''
+      install_name_tool -change @rpath/libzstd.1.dylib $out/lib/libzstd.1.dylib $bin/bin/pzstd
+    ''
+  );
+
+  outputs = [ "bin" "dev" ]
+    ++ lib.optional stdenv.hostPlatform.isUnix "man"
+    ++ [ "out" ];
+
+  passthru = {
+    updateScript = nix-update-script { };
+    tests = {
+      inherit libarchive rocksdb arrow-cpp;
+      libzip = libzip.override { withZstd = true; };
+      curl = curl.override { zstdSupport = true; };
+      python-zstd = python3Packages.zstd;
+      haskell-zstd = haskellPackages.zstd;
+      haskell-hs-zstd = haskellPackages.hs-zstd;
+    };
+  };
+
+  meta = with lib; {
+    description = "Zstandard real-time compression algorithm";
+    longDescription = ''
+      Zstd, short for Zstandard, is a fast lossless compression algorithm,
+      targeting real-time compression scenarios at zlib-level compression
+      ratio. Zstd can also offer stronger compression ratio at the cost of
+      compression speed. Speed/ratio trade-off is configurable by small
+      increment, to fit different situations. Note however that decompression
+      speed is preserved and remain roughly the same at all settings, a
+      property shared by most LZ compression algorithms, such as zlib.
+    '';
+    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.
+
+    platforms = platforms.all;
+    maintainers = with maintainers; [ orivej ];
+  };
+}
diff --git a/nixpkgs/pkgs/tools/compression/zstd/playtests-darwin.patch b/nixpkgs/pkgs/tools/compression/zstd/playtests-darwin.patch
new file mode 100644
index 000000000000..454489a24a12
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/zstd/playtests-darwin.patch
@@ -0,0 +1,40 @@
+--- a/tests/playTests.sh
++++ b/tests/playTests.sh
+@@ -112,29 +112,19 @@ case "$OS" in
+ esac
+ 
+ case "$UNAME" in
+-  Darwin) MD5SUM="md5 -r" ;;
+-  FreeBSD) MD5SUM="gmd5sum" ;;
+-  NetBSD) MD5SUM="md5 -n" ;;
+-  OpenBSD) MD5SUM="md5" ;;
+   *) MD5SUM="md5sum" ;;
+ esac
+ 
+ MTIME="stat -c %Y"
+-case "$UNAME" in
+-    Darwin | FreeBSD | OpenBSD | NetBSD) MTIME="stat -f %m" ;;
+-esac
+ 
+ assertSameMTime() {
+     MT1=$($MTIME "$1")
+     MT2=$($MTIME "$2")
+     echo MTIME $MT1 $MT2
+     [ "$MT1" = "$MT2" ] || die "mtime on $1 doesn't match mtime on $2 ($MT1 != $MT2)"
+ }
+ 
+ GET_PERMS="stat -c %a"
+-case "$UNAME" in
+-    Darwin | FreeBSD | OpenBSD | NetBSD) GET_PERMS="stat -f %Lp" ;;
+-esac
+ 
+ assertFilePermissions() {
+     STAT1=$($GET_PERMS "$1")
+@@ -967,7 +957,6 @@ $MD5SUM dirTestDict/* > tmph1
+ zstd -f --rm dirTestDict/* -D tmpDictC
+ zstd -d --rm dirTestDict/*.zst -D tmpDictC  # note : use internal checksum by default
+ case "$UNAME" in
+-  Darwin) println "md5sum -c not supported on OS-X : test skipped" ;;  # not compatible with OS-X's md5
+   *) $MD5SUM -c tmph1 ;;
+ esac
+ rm -rf dirTestDict
diff --git a/nixpkgs/pkgs/tools/compression/zsync/default.nix b/nixpkgs/pkgs/tools/compression/zsync/default.nix
new file mode 100644
index 000000000000..0de21cb9c736
--- /dev/null
+++ b/nixpkgs/pkgs/tools/compression/zsync/default.nix
@@ -0,0 +1,21 @@
+{ lib, stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  pname = "zsync";
+  version = "0.6.2";
+
+  src = fetchurl {
+    url = "http://zsync.moria.org.uk/download/${pname}-${version}.tar.bz2";
+    sha256 = "1wjslvfy76szf0mgg2i9y9q30858xyjn6v2acc24zal76d1m778b";
+  };
+
+  makeFlags = [ "AR=${stdenv.cc.bintools.targetPrefix}ar" ];
+
+  meta = with lib; {
+    homepage = "http://zsync.moria.org.uk/";
+    description = "File distribution system using the rsync algorithm";
+    license = licenses.artistic2;
+    maintainers = with maintainers; [ viric ];
+    platforms = with platforms; all;
+  };
+}