1{ stdenv, lib, fetchurl, fetchpatch
2, zlib, xz, libintl, python, gettext, ncurses, findXMLCatalogs
3, pythonSupport ? stdenv.buildPlatform == stdenv.hostPlatform
4, icuSupport ? false, icu ? null
5, enableShared ? stdenv.hostPlatform.libc != "msvcrt"
6, enableStatic ? !enableShared,
7}:
8
9stdenv.mkDerivation rec {
10 pname = "libxml2";
11 version = "2.9.10";
12
13 src = fetchurl {
14 url = "http://xmlsoft.org/sources/${pname}-${version}.tar.gz";
15 sha256 = "07xynh8hcxb2yb1fs051xrgszjvj37wnxvxgsj10rzmqzy9y3zma";
16 };
17 patches = [
18 # Upstream bugs:
19 # https://bugzilla.gnome.org/show_bug.cgi?id=789714
20 # https://gitlab.gnome.org/GNOME/libxml2/issues/64
21 # Patch from https://bugzilla.opensuse.org/show_bug.cgi?id=1065270 ,
22 # but only the UTF-8 part.
23 # Can also be mitigated by fixing malformed XML inputs, such as in
24 # https://gitlab.gnome.org/GNOME/gnumeric/merge_requests/3 .
25 # Other discussion:
26 # https://github.com/itstool/itstool/issues/22
27 # https://github.com/NixOS/nixpkgs/pull/63174
28 # https://github.com/NixOS/nixpkgs/pull/72342
29 ./utf8-xmlErrorFuncHandler.patch
30 (fetchpatch {
31 name = "CVE-2020-7595.patch";
32 url = "https://gitlab.gnome.org/GNOME/libxml2/commit/0e1a49c8907645d2e155f0d89d4d9895ac5112b5.patch";
33 sha256 = "0klvaxkzakkpyq0m44l9xrpn5kwaii194sqsivfm6zhnb9hhl15l";
34 })
35 (fetchpatch {
36 name = "CVE-2019-20388.patch";
37 url = "https://gitlab.gnome.org/GNOME/libxml2/commit/6088a74bcf7d0c42e24cff4594d804e1d3c9fbca.patch";
38 sha256 = "070s7al2r2k92320h9cdfc2097jy4kk04d0disc98ddc165r80jl";
39 })
40 ];
41
42 outputs = [ "bin" "dev" "out" "man" "doc" ]
43 ++ lib.optional pythonSupport "py"
44 ++ lib.optional (enableStatic && enableShared) "static";
45
46 buildInputs = lib.optional pythonSupport python
47 ++ lib.optional (pythonSupport && python?isPy2 && python.isPy2) gettext
48 ++ lib.optional (pythonSupport && python?isPy3 && python.isPy3) ncurses
49 ++ lib.optional (stdenv.isDarwin &&
50 pythonSupport && python?isPy2 && python.isPy2) libintl
51 # Libxml2 has an optional dependency on liblzma. However, on impure
52 # platforms, it may end up using that from /usr/lib, and thus lack a
53 # RUNPATH for that, leading to undefined references for its users.
54 ++ lib.optional stdenv.isFreeBSD xz;
55
56 propagatedBuildInputs = [ zlib findXMLCatalogs ] ++ lib.optional icuSupport icu;
57
58 configureFlags = [
59 "--exec_prefix=$dev"
60 (lib.enableFeature enableStatic "static")
61 (lib.enableFeature enableShared "shared")
62 (lib.withFeature icuSupport "icu")
63 (lib.withFeatureAs pythonSupport "python" python)
64 ];
65
66 enableParallelBuilding = true;
67
68 # disable test that's problematic with newer pythons: see
69 # https://mail.gnome.org/archives/xml/2017-August/msg00014.html
70 preCheck = lib.optionalString (pythonSupport && !(python?pythonOlder && python.pythonOlder "3.5")) ''
71 echo "" > python/tests/tstLastError.py
72 '';
73
74 doCheck = (stdenv.hostPlatform == stdenv.buildPlatform) && !stdenv.isDarwin &&
75 stdenv.hostPlatform.libc != "musl";
76
77 preInstall = lib.optionalString pythonSupport
78 ''substituteInPlace python/libxml2mod.la --replace "${python}" "$py"'';
79 installFlags = lib.optional pythonSupport
80 "pythondir=\"${placeholder ''py''}/lib/${python.libPrefix}/site-packages\"";
81
82 postFixup = ''
83 moveToOutput bin/xml2-config "$dev"
84 moveToOutput lib/xml2Conf.sh "$dev"
85 moveToOutput share/man/man1 "$bin"
86 '' + lib.optionalString (enableStatic && enableShared) ''
87 moveToOutput lib/libxml2.a "$static"
88 '';
89
90 passthru = { inherit version; pythonSupport = pythonSupport; };
91
92 meta = {
93 homepage = "http://xmlsoft.org/";
94 description = "An XML parsing library for C";
95 license = lib.licenses.mit;
96 platforms = lib.platforms.all;
97 maintainers = [ lib.maintainers.eelco ];
98 };
99}