1{ stdenv, fetchurl, fetchpatch
2, pkgconfig, makeWrapper
3, libxml2, gnutls, devicemapper, perl, python
4, iproute, iptables, readline, lvm2, utillinux, udev, libpciaccess, gettext
5, libtasn1, ebtables, libgcrypt, yajl, pmutils, libcap_ng
6, dnsmasq, libnl, libpcap, libxslt, xhtml1, numad, numactl, perlPackages
7, curl, libiconv, gmp, xen, zfs, systemd
8}:
9# if you update, also bump pythonPackages.libvirt or it will break
10stdenv.mkDerivation rec {
11 name = "libvirt-${version}";
12 version = "1.3.5";
13
14 src = fetchurl {
15 url = "http://libvirt.org/sources/${name}.tar.gz";
16 sha256 = "1j2ar5gb6xcyw1mlpm0mfpiri6www9k5myaqjina87a3xd23r8lk";
17 };
18
19 patches = [
20 ./build-on-bsd.patch
21 (fetchpatch { # see http://security.libvirt.org/2016/0001.html
22 name = "libvirt-CVE-2016-5008";
23 url = "https://libvirt.org/git/?p=libvirt.git;a=patch;h=46d27cde24b495320dc28bbf79134e0ce48c11b8";
24 sha256 = "19f6f8df57cr0sn6a1xf9ixa6vgjqmmzjf617pdj5gxy18aqn2pg";
25 })
26 ];
27
28 nativeBuildInputs = [ makeWrapper pkgconfig ];
29 buildInputs = [
30 libxml2 gnutls perl python readline
31 gettext libtasn1 libgcrypt yajl
32 libxslt xhtml1 perlPackages.XMLXPath curl libpcap
33 ] ++ stdenv.lib.optionals stdenv.isLinux [
34 libpciaccess devicemapper lvm2 utillinux udev libcap_ng
35 libnl numad numactl xen zfs systemd
36 ] ++ stdenv.lib.optionals stdenv.isDarwin [
37 libiconv gmp
38 ];
39
40 preConfigure = stdenv.lib.optionalString stdenv.isLinux ''
41 PATH=${iproute}/sbin:${iptables}/sbin:${ebtables}/sbin:${lvm2}/sbin:${udev}/sbin:$PATH
42 substituteInPlace configure --replace 'as_dummy="/bin:/usr/bin:/usr/sbin"' 'as_dummy="${numad}/bin"'
43 '' + ''
44 PATH=${dnsmasq}/bin:$PATH
45 patchShebangs . # fixes /usr/bin/python references
46 '';
47
48 configureFlags = [
49 "--localstatedir=/var"
50 "--sysconfdir=/var/lib"
51 "--with-libpcap"
52 "--with-vmware"
53 "--with-vbox"
54 "--with-test"
55 "--with-esx"
56 "--with-remote"
57 ] ++ stdenv.lib.optionals stdenv.isLinux [
58 "--with-numad"
59 "--with-macvtap"
60 "--with-virtualport"
61 "--with-init-script=redhat"
62 "--with-storage-zfs"
63 "--with-systemd-daemon"
64 ] ++ stdenv.lib.optionals stdenv.isDarwin [
65 "--with-init-script=none"
66 ];
67
68 installFlags = [
69 "localstatedir=$(TMPDIR)/var"
70 "sysconfdir=$(out)/var/lib"
71 ];
72
73 postInstall = ''
74 sed -i 's/ON_SHUTDOWN=suspend/ON_SHUTDOWN=''${ON_SHUTDOWN:-suspend}/' $out/libexec/libvirt-guests.sh
75 substituteInPlace $out/libexec/libvirt-guests.sh \
76 --replace "$out/bin" "${gettext}/bin"
77 '' + stdenv.lib.optionalString stdenv.isLinux ''
78 wrapProgram $out/sbin/libvirtd \
79 --prefix PATH : ${iptables}/sbin:${iproute}/sbin:${pmutils}/bin:${numad}/bin:${numactl}/bin
80 '';
81
82 enableParallelBuilding = true;
83
84 NIX_CFLAGS_COMPILE = "-fno-stack-protector";
85
86 meta = with stdenv.lib; {
87 homepage = http://libvirt.org/;
88 repositories.git = git://libvirt.org/libvirt.git;
89 description = ''
90 A toolkit to interact with the virtualization capabilities of recent
91 versions of Linux (and other OSes)
92 '';
93 license = licenses.lgpl2Plus;
94 platforms = platforms.unix;
95 maintainers = with maintainers; [ fpletz ];
96 };
97}