1 { lib, stdenv, fetchFromGitHub, enableUnfree ? false }:
3 stdenv.mkDerivation (finalAttrs: {
7 src = fetchFromGitHub {
8 owner = "p7zip-project";
10 rev = "v${finalAttrs.version}";
12 free = "sha256-5r7M9BVcAryZNTkqJ/BfHnSSWov1PwoZhUnLBwEbJoA=";
13 unfree = "sha256-z3qXgv/TkNRbb85Ew1OcJNxoyssfzHShc0b0/4NZOb0=";
14 }.${if enableUnfree then "unfree" else "free"};
15 # remove the unRAR related code from the src drv
16 # > the license requires that you agree to these use restrictions,
17 # > or you must remove the software (source and binary) from your hard disks
18 # https://fedoraproject.org/wiki/Licensing:Unrar
19 postFetch = lib.optionalString (!enableUnfree) ''
20 rm -r $out/CPP/7zip/Compress/Rar*
21 find $out -name makefile'*' -exec sed -i '/Rar/d' {} +
25 # Default makefile is full of impurities on Darwin. The patch doesn't hurt Linux so I'm leaving it unconditional
27 sed -i '/CC=\/usr/d' makefile.macosx_llvm_64bits
28 # Avoid writing timestamps into compressed manpages
29 # to maintain determinism.
30 substituteInPlace install.sh --replace 'gzip' 'gzip -n'
33 # I think this is a typo and should be CXX? Either way let's kill it
34 sed -i '/XX=\/usr/d' makefile.macosx_llvm_64bits
35 '' + lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
36 substituteInPlace makefile.machine \
37 --replace 'CC=gcc' 'CC=${stdenv.cc.targetPrefix}gcc' \
38 --replace 'CXX=g++' 'CXX=${stdenv.cc.targetPrefix}g++'
43 '' + lib.optionalString stdenv.hostPlatform.isDarwin ''
44 cp makefile.macosx_llvm_64bits makefile.machine
47 enableParallelBuilding = true;
48 env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-Wno-error=c++11-narrowing";
51 "DEST_BIN=${placeholder "out"}/bin"
52 "DEST_SHARE=${placeholder "lib"}/lib/p7zip"
53 "DEST_MAN=${placeholder "man"}/share/man"
54 "DEST_SHARE_DOC=${placeholder "doc"}/share/doc/p7zip"
57 outputs = [ "out" "lib" "doc" "man" ];
59 setupHook = ./setup-hook.sh;
60 passthru.updateScript = ./update.sh;
63 homepage = "https://github.com/p7zip-project/p7zip";
64 description = "New p7zip fork with additional codecs and improvements (forked from https://sourceforge.net/projects/p7zip/)";
65 license = with licenses;
66 # p7zip code is largely lgpl2Plus
67 # CPP/7zip/Compress/LzfseDecoder.cpp is bsd3
68 [ lgpl2Plus /* and */ bsd3 ] ++
69 # and CPP/7zip/Compress/Rar* are unfree with the unRAR license restriction
70 # the unRAR compression code is disabled by default
71 lib.optionals enableUnfree [ unfree ];
72 maintainers = with maintainers; [ raskin jk ];
73 platforms = platforms.unix;