summary refs log tree commit diff
path: root/pkgs/tools/archivers/7zz/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/tools/archivers/7zz/default.nix')
-rw-r--r--pkgs/tools/archivers/7zz/default.nix58
1 files changed, 51 insertions, 7 deletions
diff --git a/pkgs/tools/archivers/7zz/default.nix b/pkgs/tools/archivers/7zz/default.nix
index c93a750e48f..c4ccae0272e 100644
--- a/pkgs/tools/archivers/7zz/default.nix
+++ b/pkgs/tools/archivers/7zz/default.nix
@@ -1,4 +1,14 @@
-{ stdenv, lib, fetchurl, p7zip, uasm, useUasm ? stdenv.isx86_64 }:
+{ stdenv
+, lib
+, fetchurl
+
+, uasm
+, useUasm ? stdenv.isx86_64
+
+  # RAR code is under non-free unRAR license
+  # see the meta.license section below for more details
+, enableUnfree ? false
+}:
 
 let
   inherit (stdenv.hostPlatform) system;
@@ -14,17 +24,38 @@ stdenv.mkDerivation rec {
   version = "21.07";
 
   src = fetchurl {
-    url = "https://7-zip.org/a/7z${lib.replaceStrings [ "." ] [ "" ] version}-src.7z";
-    sha256 = "sha256-0QdNVvQVqrmdmeWXp7ZtxFXbpjSa6KTInfdkdbahKEw=";
+    url = "https://7-zip.org/a/7z${lib.replaceStrings [ "." ] [ "" ] version}-src.tar.xz";
+    sha256 = {
+      free = "sha256-SMM6kQ6AZ05s4miJjMoE4NnsXQ0tlkdWx0q2HKjhaM8=";
+      unfree = "sha256-IT1ZRAfLjvy6NmELFSykkh7aFBYzELQ5A9E+aDE+Hjk=";
+    }.${if enableUnfree then "unfree" else "free"};
+    downloadToTemp = (!enableUnfree);
+    # remove the unRAR related code from the src drv
+    # > the license requires that you agree to these use restrictions,
+    # > or you must remove the software (source and binary) from your hard disks
+    # https://fedoraproject.org/wiki/Licensing:Unrar
+    postFetch = lib.optionalString (!enableUnfree) ''
+      mkdir tmp
+      tar xf $downloadedFile -C ./tmp
+      rm -r ./tmp/CPP/7zip/Compress/Rar*
+      tar cfJ $out -C ./tmp . \
+        --sort=name \
+        --mtime="@$SOURCE_DATE_EPOCH" \
+        --owner=0 --group=0 --numeric-owner \
+        --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime
+    '';
   };
 
   sourceRoot = "CPP/7zip/Bundles/Alone2";
 
-  makeFlags = lib.optionals useUasm [ "MY_ASM=uasm" ];
+  makeFlags =
+    lib.optionals useUasm [ "MY_ASM=uasm" ] ++
+    # it's the compression code with the restriction, see DOC/License.txt
+    lib.optionals (!enableUnfree) [ "DISABLE_RAR_COMPRESS=true" ];
 
   makefile = "../../cmpl_gcc${platformSuffix}.mak";
 
-  nativeBuildInputs = [ p7zip ] ++ lib.optionals useUasm [ uasm ];
+  nativeBuildInputs = lib.optionals useUasm [ uasm ];
 
   enableParallelBuilding = true;
 
@@ -40,14 +71,27 @@ stdenv.mkDerivation rec {
   doInstallCheck = true;
 
   installCheckPhase = ''
+    runHook preInstallCheck
+
     $out/bin/7zz --help | grep ${version}
+
+    runHook postInstallCheck
   '';
 
+  passthru.updateScript = ./update.sh;
+
   meta = with lib; {
     description = "Command line archiver utility";
     homepage = "https://7-zip.org";
-    license = licenses.lgpl21Plus;
-    maintainers = with maintainers; [ anna328p peterhoeg ];
+    license = with licenses;
+      # 7zip code is largely lgpl2Plus
+      # CPP/7zip/Compress/LzfseDecoder.cpp is bsd3
+      [ lgpl2Plus /* and */ bsd3 ] ++
+      # and CPP/7zip/Compress/Rar* are unfree with the unRAR license restriction
+      # the unRAR compression code is disabled by default
+      lib.optionals enableUnfree [ unfree ];
+    maintainers = with maintainers; [ anna328p peterhoeg jk ];
     platforms = platforms.linux;
+    mainProgram = "7zz";
   };
 }