nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 stdenv,
3 lib,
4 fetchzip,
5
6 # Only useful on Linux x86/x86_64, and brings in non‐free Open Watcom
7 uasm,
8 useUasm ? false,
9
10 # RAR code is under non-free unRAR license
11 # see the meta.license section below for more details
12 enableUnfree ? false,
13
14 # For tests
15 testers,
16}:
17
18let
19 makefile =
20 {
21 aarch64-darwin = "../../cmpl_mac_arm64.mak";
22 x86_64-darwin = "../../cmpl_mac_x64.mak";
23 aarch64-linux = "../../cmpl_gcc_arm64.mak";
24 i686-linux = "../../cmpl_gcc_x86.mak";
25 x86_64-linux = "../../cmpl_gcc_x64.mak";
26 }
27 .${stdenv.hostPlatform.system} or "../../cmpl_gcc.mak"; # generic build
28in
29stdenv.mkDerivation (finalAttrs: {
30 pname = "7zz";
31 version = "25.01";
32
33 src = fetchzip {
34 url = "https://7-zip.org/a/7z${lib.replaceStrings [ "." ] [ "" ] finalAttrs.version}-src.tar.xz";
35 hash =
36 {
37 free = "sha256-A1BBdSGepobpguzokL1zpjce5EOl0zqABYciv9zCOac=";
38 unfree = "sha256-Jkj6T4tMols33uyJSOCcVmxh5iBYYCO/rq9dF4NDMko=";
39 }
40 .${if enableUnfree then "unfree" else "free"};
41 stripRoot = false;
42 # remove the unRAR related code from the src drv
43 # > the license requires that you agree to these use restrictions,
44 # > or you must remove the software (source and binary) from your hard disks
45 # https://fedoraproject.org/wiki/Licensing:Unrar
46 postFetch = lib.optionalString (!enableUnfree) ''
47 rm -r $out/CPP/7zip/Compress/Rar*
48 '';
49 };
50
51 patches = [
52 ./fix-cross-mingw-build.patch
53 ];
54
55 postPatch = lib.optionalString stdenv.hostPlatform.isMinGW ''
56 substituteInPlace CPP/7zip/7zip_gcc.mak C/7zip_gcc_c.mak \
57 --replace windres.exe ${stdenv.cc.targetPrefix}windres
58 '';
59
60 env.NIX_CFLAGS_COMPILE = toString (
61 lib.optionals stdenv.hostPlatform.isDarwin [
62 "-Wno-deprecated-copy-dtor"
63 ]
64 ++ lib.optionals stdenv.hostPlatform.isMinGW [
65 "-Wno-conversion"
66 "-Wno-unused-macros"
67 ]
68 ++ lib.optionals stdenv.cc.isClang [
69 "-Wno-declaration-after-statement"
70 (lib.optionals (lib.versionAtLeast (lib.getVersion stdenv.cc.cc) "13") [
71 "-Wno-reserved-identifier"
72 "-Wno-unused-but-set-variable"
73 ])
74 (lib.optionals (lib.versionAtLeast (lib.getVersion stdenv.cc.cc) "16") [
75 "-Wno-unsafe-buffer-usage"
76 "-Wno-cast-function-type-strict"
77 ])
78 # These three probably started to appear with clang 20 or 21:
79 "-Wno-c++-keyword"
80 "-Wno-implicit-void-ptr-cast"
81 "-Wno-nrvo"
82 ]
83 );
84
85 inherit makefile;
86
87 makeFlags = [
88 "CC=${stdenv.cc.targetPrefix}cc"
89 "CXX=${stdenv.cc.targetPrefix}c++"
90 ]
91 ++ lib.optionals useUasm [ "MY_ASM=uasm" ]
92 ++ lib.optionals (!useUasm && stdenv.hostPlatform.isx86) [ "USE_ASM=" ]
93 # it's the compression code with the restriction, see DOC/License.txt
94 ++ lib.optionals (!enableUnfree) [ "DISABLE_RAR_COMPRESS=true" ]
95 ++ lib.optionals (stdenv.hostPlatform.isMinGW) [
96 "IS_MINGW=1"
97 "MSYSTEM=1"
98 ];
99
100 nativeBuildInputs = lib.optionals useUasm [ uasm ];
101
102 setupHook = ./setup-hook.sh;
103
104 enableParallelBuilding = true;
105
106 preBuild = "cd CPP/7zip/Bundles/Alone2";
107
108 installPhase = ''
109 runHook preInstall
110
111 install -Dm555 -t $out/bin b/*/7zz${stdenv.hostPlatform.extensions.executable}
112 install -Dm444 -t $out/share/doc/7zz ../../../../DOC/*.txt
113
114 runHook postInstall
115 '';
116
117 passthru = {
118 updateScript = ./update.sh;
119 tests.version = testers.testVersion {
120 package = finalAttrs.finalPackage;
121 command = "7zz --help";
122 };
123 };
124
125 meta = {
126 description = "Command line archiver utility";
127 homepage = "https://7-zip.org";
128 license =
129 with lib.licenses;
130 # 7zip code is largely lgpl2Plus
131 # CPP/7zip/Compress/LzfseDecoder.cpp is bsd3
132 [
133 lgpl2Plus # and
134 bsd3
135 ]
136 ++
137 # and CPP/7zip/Compress/Rar* are unfree with the unRAR license restriction
138 # the unRAR compression code is disabled by default
139 lib.optionals enableUnfree [ unfree ];
140 maintainers = with lib.maintainers; [
141 anna328p
142 jk
143 peterhoeg
144 ];
145 platforms = with lib.platforms; unix ++ windows;
146 mainProgram = "7zz";
147 };
148})