base16-schemes: unstable-2024-06-21 -> unstable-2024-11-12
[NixPkgs.git] / pkgs / by-name / li / libarchive / package.nix
blob8703c1a4faba037b431cc86b66a36758d58c99cc
1 { lib
2 , stdenv
3 , fetchFromGitHub
4 , acl
5 , attr
6 , autoreconfHook
7 , bzip2
8 , e2fsprogs
9 , glibcLocalesUtf8
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
22 # for passthru.tests
23 , cmake
24 , nix
25 , samba
27 # for passthru.lore
28 , binlore
31 assert xarSupport -> libxml2 != null;
32 stdenv.mkDerivation (finalAttrs: {
33   pname = "libarchive";
34   version = "3.7.7";
36   src = fetchFromGitHub {
37     owner = "libarchive";
38     repo = "libarchive";
39     rev = "v${finalAttrs.version}";
40     hash = "sha256-maV2+Whi4aDG1VLAYpOTxluO9I0zNiZ8fA3w7epGlDg=";
41   };
43   outputs = [ "out" "lib" "dev" ];
45   postPatch = let
46     skipTestPaths = [
47       # test won't work in nix sandbox
48       "libarchive/test/test_write_disk_perms.c"
49       # the filesystem does not necessarily have sparse capabilities
50       "libarchive/test/test_sparse_basic.c"
51       # the filesystem does not necessarily have hardlink capabilities
52       "libarchive/test/test_write_disk_hardlink.c"
53       # access-time-related tests flakey on some systems
54       "cpio/test/test_option_a.c"
55       "cpio/test/test_option_t.c"
56     ] ++ lib.optionals (stdenv.hostPlatform.isAarch64 && stdenv.hostPlatform.isLinux) [
57       # only on some aarch64-linux systems?
58       "cpio/test/test_basic.c"
59       "cpio/test/test_format_newc.c"
60     ];
61     removeTest = testPath: ''
62       substituteInPlace Makefile.am --replace-fail "${testPath}" ""
63       rm "${testPath}"
64     '';
65   in ''
66     substituteInPlace Makefile.am --replace-fail '/bin/pwd' "$(type -P pwd)"
68     ${lib.concatStringsSep "\n" (map removeTest skipTestPaths)}
69   '';
71   nativeBuildInputs = [
72     autoreconfHook
73     glibcLocalesUtf8 # test_I test requires an UTF-8 locale
74     pkg-config
75   ];
77   buildInputs =  [
78     bzip2
79     lzo
80     openssl
81     xz
82     zlib
83     zstd
84   ] ++ lib.optional stdenv.hostPlatform.isUnix sharutils
85     ++ lib.optionals stdenv.hostPlatform.isLinux [ acl attr e2fsprogs ]
86     ++ lib.optional xarSupport libxml2;
88   # Without this, pkg-config-based dependencies are unhappy
89   propagatedBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [ attr acl ];
91   configureFlags = lib.optional (!xarSupport) "--without-xml2";
93   preBuild = lib.optionalString stdenv.hostPlatform.isCygwin ''
94     echo "#include <windows.h>" >> config.h
95   '';
97   # https://github.com/libarchive/libarchive/issues/1475
98   doCheck = !stdenv.hostPlatform.isMusl;
100   preCheck = ''
101     # Need an UTF-8 locale for test_I test.
102     export LANG=en_US.UTF-8
103   '';
105   preFixup = ''
106     sed -i $lib/lib/libarchive.la \
107       -e 's|-lcrypto|-L${lib.getLib openssl}/lib -lcrypto|' \
108       -e 's|-llzo2|-L${lzo}/lib -llzo2|'
109   '';
111   enableParallelBuilding = true;
113   meta = with lib; {
114     homepage = "http://libarchive.org";
115     description = "Multi-format archive and compression library";
116     longDescription = ''
117       The libarchive project develops a portable, efficient C library that can
118       read and write streaming archives in a variety of formats. It also
119       includes implementations of the common tar, cpio, and zcat command-line
120       tools that use the libarchive library.
121     '';
122     changelog = "https://github.com/libarchive/libarchive/releases/tag/v${finalAttrs.version}";
123     license = licenses.bsd3;
124     maintainers = with maintainers; [ jcumming AndersonTorres ];
125     platforms = platforms.all;
126     inherit (acl.meta) badPlatforms;
127   };
129   passthru.tests = {
130     inherit cmake nix samba;
131   };
133   # bsdtar is detected as "cannot" because its exec is internal to
134   # calls it makes into libarchive itself. If binlore gains support
135   # for detecting another layer down into libraries, this can be cut.
136   passthru.binlore.out = binlore.synthesize finalAttrs.finalPackage ''
137     execer can bin/bsdtar
138   '';