@@ -1,4 +1,14 @@
1−{ stdenv, lib, fetchurl, p7zip, uasm, useUasm ? stdenv.isx86_64 }:
1+{ stdenv
2+, lib
3+, fetchurl
4+
5+, uasm
6+, useUasm ? stdenv.isx86_64
7+
8+ # RAR code is under non-free unRAR license
9+ # see the meta.license section below for more details
10+, enableUnfree ? false
11+}:
212
313let
414 inherit (stdenv.hostPlatform) system;
@@ -14,17 +24,38 @@ stdenv.mkDerivation rec {
1424 version = "21.07";
1525
1626 src = fetchurl {
17− url = "https://7-zip.org/a/7z${lib.replaceStrings [ "." ] [ "" ] version}-src.7z";
18− sha256 = "sha256-0QdNVvQVqrmdmeWXp7ZtxFXbpjSa6KTInfdkdbahKEw=";
27+ url = "https://7-zip.org/a/7z${lib.replaceStrings [ "." ] [ "" ] version}-src.tar.xz";
28+ sha256 = {
29+ free = "sha256-SMM6kQ6AZ05s4miJjMoE4NnsXQ0tlkdWx0q2HKjhaM8=";
30+ unfree = "sha256-IT1ZRAfLjvy6NmELFSykkh7aFBYzELQ5A9E+aDE+Hjk=";
31+ }.${if enableUnfree then "unfree" else "free"};
32+ downloadToTemp = (!enableUnfree);
33+ # remove the unRAR related code from the src drv
34+ # > the license requires that you agree to these use restrictions,
35+ # > or you must remove the software (source and binary) from your hard disks
36+ # https://fedoraproject.org/wiki/Licensing:Unrar
37+ postFetch = lib.optionalString (!enableUnfree) ''
38+ mkdir tmp
39+ tar xf $downloadedFile -C ./tmp
40+ rm -r ./tmp/CPP/7zip/Compress/Rar*
41+ tar cfJ $out -C ./tmp . \
42+ --sort=name \
43+ --mtime="@$SOURCE_DATE_EPOCH" \
44+ --owner=0 --group=0 --numeric-owner \
45+ --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime
46+ '';
1947 };
2048
2149 sourceRoot = "CPP/7zip/Bundles/Alone2";
2250
23− makeFlags = lib.optionals useUasm [ "MY_ASM=uasm" ];
51+ makeFlags =
52+ lib.optionals useUasm [ "MY_ASM=uasm" ] ++
53+ # it's the compression code with the restriction, see DOC/License.txt
54+ lib.optionals (!enableUnfree) [ "DISABLE_RAR_COMPRESS=true" ];
2455
2556 makefile = "../../cmpl_gcc${platformSuffix}.mak";
2657
27− nativeBuildInputs = [ p7zip ] ++ lib.optionals useUasm [ uasm ];
58+ nativeBuildInputs = lib.optionals useUasm [ uasm ];
2859
2960 enableParallelBuilding = true;
3061
@@ -40,14 +71,27 @@ stdenv.mkDerivation rec {
4071 doInstallCheck = true;
4172
4273 installCheckPhase = ''
74+ runHook preInstallCheck
75+
4376 $out/bin/7zz --help | grep ${version}
77+
78+ runHook postInstallCheck
4479 '';
4580
81+ passthru.updateScript = ./update.sh;
82+
4683 meta = with lib; {
4784 description = "Command line archiver utility";
4885 homepage = "https://7-zip.org";
49− license = licenses.lgpl21Plus;
50− maintainers = with maintainers; [ anna328p peterhoeg ];
86+ license = with licenses;
87+ # 7zip code is largely lgpl2Plus
88+ # CPP/7zip/Compress/LzfseDecoder.cpp is bsd3
89+ [ lgpl2Plus /* and */ bsd3 ] ++
90+ # and CPP/7zip/Compress/Rar* are unfree with the unRAR license restriction
91+ # the unRAR compression code is disabled by default
92+ lib.optionals enableUnfree [ unfree ];
93+ maintainers = with maintainers; [ anna328p peterhoeg jk ];
5194 platforms = platforms.linux;
95+ mainProgram = "7zz";
5296 };
5397}