5 # Only used for Linux's x86/x86_64
7 , useUasm ? (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86)
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 # We need at minimum 10.13 here because of utimensat, however since
81 # we need a bump anyway, let's set the same minimum version as the one in
82 # aarch64-darwin so we don't need additional changes for it
83 ++ lib.optionals stdenv.hostPlatform.isDarwin [ "MACOSX_DEPLOYMENT_TARGET=10.16" ]
84 # it's the compression code with the restriction, see DOC/License.txt
85 ++ lib.optionals (!enableUnfree) [ "DISABLE_RAR_COMPRESS=true" ]
86 ++ lib.optionals (stdenv.hostPlatform.isMinGW) [ "IS_MINGW=1" "MSYSTEM=1" ];
88 nativeBuildInputs = lib.optionals useUasm [ uasm ];
90 setupHook = ./setup-hook.sh;
92 enableParallelBuilding = true;
94 preBuild = "cd CPP/7zip/Bundles/Alone2";
99 install -Dm555 -t $out/bin b/*/7zz${stdenv.hostPlatform.extensions.executable}
100 install -Dm444 -t $out/share/doc/${finalAttrs.pname} ../../../../DOC/*.txt
106 updateScript = ./update.sh;
107 tests.version = testers.testVersion {
108 package = finalAttrs.finalPackage;
109 command = "7zz --help";
114 description = "Command line archiver utility";
115 homepage = "https://7-zip.org";
116 license = with lib.licenses;
117 # 7zip code is largely lgpl2Plus
118 # CPP/7zip/Compress/LzfseDecoder.cpp is bsd3
119 [ lgpl2Plus /* and */ bsd3 ] ++
120 # and CPP/7zip/Compress/Rar* are unfree with the unRAR license restriction
121 # the unRAR compression code is disabled by default
122 lib.optionals enableUnfree [ unfree ];
123 maintainers = with lib.maintainers; [ anna328p jk peterhoeg ];
124 platforms = with lib.platforms; unix ++ windows;