1{ stdenv, lib, fetchurl, fetchpatch
2, zlib, xz, python, 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?isPy3 && python.isPy3) ncurses
48 # Libxml2 has an optional dependency on liblzma. However, on impure
49 # platforms, it may end up using that from /usr/lib, and thus lack a
50 # RUNPATH for that, leading to undefined references for its users.
51 ++ lib.optional stdenv.isFreeBSD xz;
52
53 propagatedBuildInputs = [ zlib findXMLCatalogs ] ++ lib.optional icuSupport icu;
54
55 configureFlags = [
56 "--exec_prefix=$dev"
57 (lib.enableFeature enableStatic "static")
58 (lib.enableFeature enableShared "shared")
59 (lib.withFeature icuSupport "icu")
60 (lib.withFeatureAs pythonSupport "python" python)
61 ];
62
63 enableParallelBuilding = true;
64
65 # disable test that's problematic with newer pythons: see
66 # https://mail.gnome.org/archives/xml/2017-August/msg00014.html
67 preCheck = lib.optionalString (pythonSupport && !(python?pythonOlder && python.pythonOlder "3.5")) ''
68 echo "" > python/tests/tstLastError.py
69 '';
70
71 doCheck = (stdenv.hostPlatform == stdenv.buildPlatform) && !stdenv.isDarwin &&
72 stdenv.hostPlatform.libc != "musl";
73
74 preInstall = lib.optionalString pythonSupport
75 ''substituteInPlace python/libxml2mod.la --replace "${python}" "$py"'';
76 installFlags = lib.optional pythonSupport
77 "pythondir=\"${placeholder ''py''}/lib/${python.libPrefix}/site-packages\"";
78
79 postFixup = ''
80 moveToOutput bin/xml2-config "$dev"
81 moveToOutput lib/xml2Conf.sh "$dev"
82 moveToOutput share/man/man1 "$bin"
83 '' + lib.optionalString (enableStatic && enableShared) ''
84 moveToOutput lib/libxml2.a "$static"
85 '';
86
87 passthru = { inherit version; pythonSupport = pythonSupport; };
88
89 meta = {
90 homepage = http://xmlsoft.org/;
91 description = "An XML parsing library for C";
92 license = lib.licenses.mit;
93 platforms = lib.platforms.all;
94 maintainers = [ lib.maintainers.eelco ];
95 };
96}