{stdenv, lib, fetchurl, pythonPackages
, gnutar, unzip, lhasa, rpm, binutils, cpio, gzip, cabextract, unrar, unshield
, bzip2, xz, lzip
# unsafe:
# ,p7zip
# unzip is no longer handled by p7zip, since it's unsafe
, unzipSupport ? true
, unrarSupport ? false }:

let
  # p7zip
  archivers = lib.makeBinPath ([ gnutar lhasa rpm binutils cpio gzip cabextract unshield ]
                               ++ lib.optional (unzipSupport) unzip
                               ++ lib.optional (unrarSupport) unrar
                               ++ [ bzip2 xz lzip ]);

in pythonPackages.buildPythonApplication rec {
  pname = "dtrx";
  version = "7.1";

  src = fetchurl {
    url = "https://brettcsmith.org/2007/dtrx/dtrx-${version}.tar.gz";
    sha256 = "15yf4n27zbhvv0byfv3i89wl5zn6jc2wbc69lk5a3m6rx54gx6hw";
  };

  postInstall = ''
    wrapProgram "$out/bin/dtrx" --prefix PATH : "${archivers}"
  '';

  meta = with stdenv.lib; {
    description = "Do The Right Extraction: A tool for taking the hassle out of extracting archives";
    homepage = "https://brettcsmith.org/2007/dtrx/";
    license = licenses.gpl3Plus;
    maintainers = [ maintainers.spwhitt ];
    platforms = platforms.all;
  };
}

{stdenv, lib, fetchurl, pythonPackages
, gnutar, unzip, lhasa, rpm, binutils, cpio, gzip, p7zip, cabextract, unrar, unshield
, bzip2, xz, lzip
# unzip is handled by p7zip
, unzipSupport ? false
, unrarSupport ? false }:

let
  archivers = lib.makeBinPath ([ gnutar lhasa rpm binutils cpio gzip p7zip cabextract unshield ]
  ++ lib.optional (unzipSupport) unzip
  ++ lib.optional (unrarSupport) unrar
  ++ [ bzip2 xz lzip ]);

in pythonPackages.buildPythonApplication rec {
  pname = "dtrx";
  version = "7.1";

  src = fetchurl {
    url = "https://brettcsmith.org/2007/dtrx/dtrx-${version}.tar.gz";
    sha256 = "15yf4n27zbhvv0byfv3i89wl5zn6jc2wbc69lk5a3m6rx54gx6hw";
  };

  postInstall = ''
    wrapProgram "$out/bin/dtrx" --prefix PATH : "${archivers}"
  '';

  meta = with stdenv.lib; {
    description = "Do The Right Extraction: A tool for taking the hassle out of extracting archives";
    homepage = "https://brettcsmith.org/2007/dtrx/";
    license = licenses.gpl3Plus;
    maintainers = [ maintainers.spwhitt ];
    platforms = platforms.all;
  };
}

Revert "dtrx: remove p7zip, since it's unsafe"
Revert "dtrx: remove p7zip, since it's unsafe"

This reverts commit 9b3ca0c6149bb222da800a89cf9b6b2bc838dc4c.
p7zip is now switched to a maintained fork
