1{ lib
2, stdenv
3, fetchFromGitHub
4, fetchpatch
5, acl
6, attr
7, autoreconfHook
8, bzip2
9, e2fsprogs
10, lzo
11, openssl
12, pkg-config
13, sharutils
14, xz
15, zlib
16, zstd
17# Optional but increases closure only negligibly. Also, while libxml2 builds
18# fine on windows, libarchive has trouble linking windows things it depends on
19# for some reason.
20, xarSupport ? stdenv.hostPlatform.isUnix, libxml2
21
22# for passthru.tests
23, cmake
24, nix
25, samba
26, buildPackages
27}:
28
29let
30 autoreconfHook = buildPackages.autoreconfHook269;
31in
32assert xarSupport -> libxml2 != null;
33(stdenv.mkDerivation (finalAttrs: {
34 pname = "libarchive";
35 version = "3.6.2";
36
37 src = fetchFromGitHub {
38 owner = "libarchive";
39 repo = "libarchive";
40 rev = "v${finalAttrs.version}";
41 hash = "sha256-wQbA6vlXH8pnpY7LJLkjrRFEBpcaPR1SqxnK71UVwxg=";
42 };
43
44 outputs = [ "out" "lib" "dev" ];
45
46 postPatch = let
47 skipTestPaths = [
48 # test won't work in nix sandbox
49 "libarchive/test/test_write_disk_perms.c"
50 # the filesystem does not necessarily have sparse capabilities
51 "libarchive/test/test_sparse_basic.c"
52 # the filesystem does not necessarily have hardlink capabilities
53 "libarchive/test/test_write_disk_hardlink.c"
54 # access-time-related tests flakey on some systems
55 "cpio/test/test_option_a.c"
56 "cpio/test/test_option_t.c"
57 ];
58 removeTest = testPath: ''
59 substituteInPlace Makefile.am --replace "${testPath}" ""
60 rm "${testPath}"
61 '';
62 in ''
63 substituteInPlace Makefile.am --replace '/bin/pwd' "$(type -P pwd)"
64
65 ${lib.concatStringsSep "\n" (map removeTest skipTestPaths)}
66 '';
67
68 nativeBuildInputs = [
69 autoreconfHook
70 pkg-config
71 ];
72
73 buildInputs = [
74 bzip2
75 lzo
76 openssl
77 xz
78 zlib
79 zstd
80 ] ++ lib.optional stdenv.hostPlatform.isUnix sharutils
81 ++ lib.optionals stdenv.isLinux [ acl attr e2fsprogs ]
82 ++ lib.optional xarSupport libxml2;
83
84 # Without this, pkg-config-based dependencies are unhappy
85 propagatedBuildInputs = lib.optionals stdenv.isLinux [ attr acl ];
86
87 configureFlags = lib.optional (!xarSupport) "--without-xml2";
88
89 preBuild = lib.optionalString stdenv.isCygwin ''
90 echo "#include <windows.h>" >> config.h
91 '';
92
93 # https://github.com/libarchive/libarchive/issues/1475
94 doCheck = !stdenv.hostPlatform.isMusl;
95
96 preFixup = ''
97 sed -i $lib/lib/libarchive.la \
98 -e 's|-lcrypto|-L${lib.getLib openssl}/lib -lcrypto|' \
99 -e 's|-llzo2|-L${lzo}/lib -llzo2|'
100 '';
101
102 enableParallelBuilding = true;
103
104 meta = with lib; {
105 homepage = "http://libarchive.org";
106 description = "Multi-format archive and compression library";
107 longDescription = ''
108 The libarchive project develops a portable, efficient C library that can
109 read and write streaming archives in a variety of formats. It also
110 includes implementations of the common tar, cpio, and zcat command-line
111 tools that use the libarchive library.
112 '';
113 changelog = "https://github.com/libarchive/libarchive/releases/tag/v${finalAttrs.version}";
114 license = licenses.bsd3;
115 maintainers = with maintainers; [ jcumming AndersonTorres ];
116 platforms = platforms.all;
117 };
118
119 passthru.tests = {
120 inherit cmake nix samba;
121 };
122})).overrideAttrs(previousAttrs:
123 assert previousAttrs.version == "3.6.2";
124 lib.optionalAttrs stdenv.hostPlatform.isStatic {
125 patches = [
126 # fixes static linking; upstream in releases after 3.6.2
127 # https://github.com/libarchive/libarchive/pull/1825 merged upstream
128 (fetchpatch {
129 name = "001-only-add-iconv-to-pc-file-if-needed.patch";
130 url = "https://github.com/libarchive/libarchive/commit/1f35c466aaa9444335a1b854b0b7223b0d2346c2.patch";
131 hash = "sha256-lb+zwWSH6/MLUIROvu9I/hUjSbb2jOWO755WC/r+lbY=";
132 })
133 ];
134 })