5 # Only useful on Linux x86/x86_64, and brings in nonāfree Open Watcom
9 # RAR code is under non-free unRAR license
10 # see the meta.license section below for more details
11 , enableUnfree ? false
19 aarch64-darwin = "../../cmpl_mac_arm64.mak";
20 x86_64-darwin = "../../cmpl_mac_x64.mak";
21 aarch64-linux = "../../cmpl_gcc_arm64.mak";
22 i686-linux = "../../cmpl_gcc_x86.mak";
23 x86_64-linux = "../../cmpl_gcc_x64.mak";
24 }.${stdenv.hostPlatform.system} or "../../cmpl_gcc.mak"; # generic build
26 stdenv.mkDerivation (finalAttrs: {
31 url = "https://7-zip.org/a/7z${lib.replaceStrings [ "." ] [ "" ] finalAttrs.version}-src.tar.xz";
33 free = "sha256-2lv2Z4rrjmawD6aI8TmrACgo62StD720WQWOa0/u7KE=";
34 unfree = "sha256-f6hibHeTlF6RRnFiC7tOZ/A+IQdjhIrxYq6JrDVhnYI=";
35 }.${if enableUnfree then "unfree" else "free"};
37 # remove the unRAR related code from the src drv
38 # > the license requires that you agree to these use restrictions,
39 # > or you must remove the software (source and binary) from your hard disks
40 # https://fedoraproject.org/wiki/Licensing:Unrar
41 postFetch = lib.optionalString (!enableUnfree) ''
42 rm -r $out/CPP/7zip/Compress/Rar*
47 ./fix-cross-mingw-build.patch
50 postPatch = lib.optionalString stdenv.hostPlatform.isMinGW ''
51 substituteInPlace CPP/7zip/7zip_gcc.mak C/7zip_gcc_c.mak \
52 --replace windres.exe ${stdenv.cc.targetPrefix}windres
55 env.NIX_CFLAGS_COMPILE = toString (lib.optionals stdenv.hostPlatform.isDarwin [
56 "-Wno-deprecated-copy-dtor"
57 ] ++ lib.optionals stdenv.hostPlatform.isMinGW [
60 ] ++ lib.optionals stdenv.cc.isClang [
61 "-Wno-declaration-after-statement"
62 (lib.optionals (lib.versionAtLeast (lib.getVersion stdenv.cc.cc) "13") [
63 "-Wno-reserved-identifier"
64 "-Wno-unused-but-set-variable"
66 (lib.optionals (lib.versionAtLeast (lib.getVersion stdenv.cc.cc) "16") [
67 "-Wno-unsafe-buffer-usage"
68 "-Wno-cast-function-type-strict"
76 "CC=${stdenv.cc.targetPrefix}cc"
77 "CXX=${stdenv.cc.targetPrefix}c++"
79 ++ lib.optionals useUasm [ "MY_ASM=uasm" ]
80 ++ lib.optionals (!useUasm && stdenv.hostPlatform.isx86) [ "USE_ASM=" ]
81 # We need at minimum 10.13 here because of utimensat, however since
82 # we need a bump anyway, let's set the same minimum version as the one in
83 # aarch64-darwin so we don't need additional changes for it
84 ++ lib.optionals stdenv.hostPlatform.isDarwin [ "MACOSX_DEPLOYMENT_TARGET=10.16" ]
85 # it's the compression code with the restriction, see DOC/License.txt
86 ++ lib.optionals (!enableUnfree) [ "DISABLE_RAR_COMPRESS=true" ]
87 ++ lib.optionals (stdenv.hostPlatform.isMinGW) [ "IS_MINGW=1" "MSYSTEM=1" ];
89 nativeBuildInputs = lib.optionals useUasm [ uasm ];
91 setupHook = ./setup-hook.sh;
93 enableParallelBuilding = true;
95 preBuild = "cd CPP/7zip/Bundles/Alone2";
100 install -Dm555 -t $out/bin b/*/7zz${stdenv.hostPlatform.extensions.executable}
101 install -Dm444 -t $out/share/doc/${finalAttrs.pname} ../../../../DOC/*.txt
107 updateScript = ./update.sh;
108 tests.version = testers.testVersion {
109 package = finalAttrs.finalPackage;
110 command = "7zz --help";
115 description = "Command line archiver utility";
116 homepage = "https://7-zip.org";
117 license = with lib.licenses;
118 # 7zip code is largely lgpl2Plus
119 # CPP/7zip/Compress/LzfseDecoder.cpp is bsd3
120 [ lgpl2Plus /* and */ bsd3 ] ++
121 # and CPP/7zip/Compress/Rar* are unfree with the unRAR license restriction
122 # the unRAR compression code is disabled by default
123 lib.optionals enableUnfree [ unfree ];
124 maintainers = with lib.maintainers; [ anna328p jk peterhoeg ];
125 platforms = with lib.platforms; unix ++ windows;