lol
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}:
27
28assert xarSupport -> libxml2 != null;
29stdenv.mkDerivation (finalAttrs: {
30 pname = "libarchive";
31 version = "3.7.2";
32
33 src = fetchFromGitHub {
34 owner = "libarchive";
35 repo = "libarchive";
36 rev = "v${finalAttrs.version}";
37 hash = "sha256-p2JgJ/rvqaQ6yyXSh+ehScUH565ud5bQncl+lOnsWfc=";
38 };
39
40 patches = [
41 # Pull fix for test failure on 32-bit systems:
42 (fetchpatch {
43 name = "32-bit-tests-fix.patch";
44 url = "https://github.com/libarchive/libarchive/commit/3bd918d92f8c34ba12de9c6604d96f9e262a59fc.patch";
45 hash = "sha256-RM3xFM6S2DkM5DJ0kAba8eLzEXuY5/7AaU06maHJ6rM=";
46 })
47 ];
48
49 outputs = [ "out" "lib" "dev" ];
50
51 postPatch = let
52 skipTestPaths = [
53 # test won't work in nix sandbox
54 "libarchive/test/test_write_disk_perms.c"
55 # the filesystem does not necessarily have sparse capabilities
56 "libarchive/test/test_sparse_basic.c"
57 # the filesystem does not necessarily have hardlink capabilities
58 "libarchive/test/test_write_disk_hardlink.c"
59 # access-time-related tests flakey on some systems
60 "cpio/test/test_option_a.c"
61 "cpio/test/test_option_t.c"
62 ];
63 removeTest = testPath: ''
64 substituteInPlace Makefile.am --replace "${testPath}" ""
65 rm "${testPath}"
66 '';
67 in ''
68 substituteInPlace Makefile.am --replace '/bin/pwd' "$(type -P pwd)"
69
70 ${lib.concatStringsSep "\n" (map removeTest skipTestPaths)}
71 '';
72
73 nativeBuildInputs = [
74 autoreconfHook
75 pkg-config
76 ];
77
78 buildInputs = [
79 bzip2
80 lzo
81 openssl
82 xz
83 zlib
84 zstd
85 ] ++ lib.optional stdenv.hostPlatform.isUnix sharutils
86 ++ lib.optionals stdenv.isLinux [ acl attr e2fsprogs ]
87 ++ lib.optional xarSupport libxml2;
88
89 # Without this, pkg-config-based dependencies are unhappy
90 propagatedBuildInputs = lib.optionals stdenv.isLinux [ attr acl ];
91
92 configureFlags = lib.optional (!xarSupport) "--without-xml2";
93
94 preBuild = lib.optionalString stdenv.isCygwin ''
95 echo "#include <windows.h>" >> config.h
96 '';
97
98 # https://github.com/libarchive/libarchive/issues/1475
99 doCheck = !stdenv.hostPlatform.isMusl;
100
101 preFixup = ''
102 sed -i $lib/lib/libarchive.la \
103 -e 's|-lcrypto|-L${lib.getLib openssl}/lib -lcrypto|' \
104 -e 's|-llzo2|-L${lzo}/lib -llzo2|'
105 '';
106
107 enableParallelBuilding = true;
108
109 meta = with lib; {
110 homepage = "http://libarchive.org";
111 description = "Multi-format archive and compression library";
112 longDescription = ''
113 The libarchive project develops a portable, efficient C library that can
114 read and write streaming archives in a variety of formats. It also
115 includes implementations of the common tar, cpio, and zcat command-line
116 tools that use the libarchive library.
117 '';
118 changelog = "https://github.com/libarchive/libarchive/releases/tag/v${finalAttrs.version}";
119 license = licenses.bsd3;
120 maintainers = with maintainers; [ jcumming AndersonTorres ];
121 platforms = platforms.all;
122 };
123
124 passthru.tests = {
125 inherit cmake nix samba;
126 };
127})