@@ -0,0 +1,160 @@
1+{ stdenv, fetchurl, fetchgit
2+, pkgconfig, makeWrapper, libtool, autoconf, automake, fetchpatch
3+, coreutils, libxml2, gnutls, perl, python2, attr
4+, iproute, iptables, readline, lvm2, utillinux, systemd, libpciaccess, gettext
5+, libtasn1, ebtables, libgcrypt, yajl, pmutils, libcap_ng, libapparmor
6+, dnsmasq, libnl, libpcap, libxslt, xhtml1, numad, numactl, perlPackages
7+, curl, libiconv, gmp, zfs, parted, bridge-utils, dmidecode
8+, enableXen ? false, xen ? null
9+, enableIscsi ? false, openiscsi
10+, enableCeph ? false, ceph
11+}:
12+
13+with stdenv.lib;
14+
15+# if you update, also bump <nixpkgs/pkgs/development/python-modules/libvirt/default.nix> and SysVirt in <nixpkgs/pkgs/top-level/perl-packages.nix>
16+let
17+ buildFromTarball = stdenv.isDarwin;
18+in stdenv.mkDerivation rec {
19+ pname = "libvirt";
20+ version = "5.4.0";
21+
22+ src =
23+ if buildFromTarball then
24+ fetchurl {
25+ url = "http://libvirt.org/sources/${pname}-${version}.tar.xz";
26+ sha256 = "0ywf8m9yz2hxnic7fylzlmgy4m353r4vv5zsvp89zq5yh4h81yhw";
27+ }
28+ else
29+ fetchgit {
30+ url = git://libvirt.org/libvirt.git;
31+ rev = "v${version}";
32+ sha256 = "1dja1mf295w0sl83zag62c4j55cfbzzfbhdxpkyv2zm3zv0mwdyc";
33+ fetchSubmodules = true;
34+ };
35+
36+ patches = optionals (!stdenv.isDarwin) [
37+ (fetchpatch {
38+ name = "5.4.0-CVE-2019-10161.patch";
39+ url = "https://libvirt.org/git/?p=libvirt.git;a=patch;h=aed6a032cead4386472afb24b16196579e239580";
40+ sha256 = "19k9z9xx68nf03igbgy1imxnlp5ppj7cgdbq9kri3s834hkjcygs";
41+ })
42+ ] ++ [
43+ (fetchpatch {
44+ name = "5.4.0-CVE-2019-10166.patch";
45+ url = "https://libvirt.org/git/?p=libvirt.git;a=patch;h=db0b78457f183e4c7ac45bc94de86044a1e2056a";
46+ sha256 = "17pd1rab2mxj4q0vg30vi2gh78mf52ik1p5l12wrghb0wjf7swml";
47+ })
48+ (fetchpatch {
49+ name = "5.4.0-CVE-2019-10167.patch";
50+ url = "https://libvirt.org/git/?p=libvirt.git;a=patch;h=8afa68bac0cf99d1f8aaa6566685c43c22622f26";
51+ sha256 = "0hgbwk0y2n6ihzjk8vqabhw914axjqgzcb7c5xx893r86c54c0ml";
52+ })
53+ (fetchpatch {
54+ name = "5.4.0-CVE-2019-10168.patch";
55+ url = "https://libvirt.org/git/?p=libvirt.git;a=patch;h=bf6c2830b6c338b1f5699b095df36f374777b291";
56+ sha256 = "0s4hc3hsjncx1852ndjas1nng9v23pxf4mi1jxcajsqvhw89la0g";
57+ })
58+ ];
59+
60+ nativeBuildInputs = [ makeWrapper pkgconfig ];
61+ buildInputs = [
62+ libxml2 gnutls perl python2 readline gettext libtasn1 libgcrypt yajl
63+ libxslt xhtml1 perlPackages.XMLXPath curl libpcap
64+ ] ++ optionals (!buildFromTarball) [
65+ libtool autoconf automake
66+ ] ++ optionals stdenv.isLinux [
67+ libpciaccess lvm2 utillinux systemd libnl numad zfs
68+ libapparmor libcap_ng numactl attr parted
69+ ] ++ optionals (enableXen && stdenv.isLinux && stdenv.isx86_64) [
70+ xen
71+ ] ++ optionals enableIscsi [
72+ openiscsi
73+ ] ++ optionals enableCeph [
74+ ceph
75+ ] ++ optionals stdenv.isDarwin [
76+ libiconv gmp
77+ ];
78+
79+ preConfigure = ''
80+ ${ optionalString (!buildFromTarball) "./bootstrap --no-git --gnulib-srcdir=$(pwd)/.gnulib" }
81+ PATH=${stdenv.lib.makeBinPath ([ dnsmasq ] ++ optionals stdenv.isLinux [ iproute iptables ebtables lvm2 systemd numad ] ++ optionals enableIscsi [ openiscsi ])}:$PATH
82+ # the path to qemu-kvm will be stored in VM's .xml and .save files
83+ # do not use "''${qemu_kvm}/bin/qemu-kvm" to avoid bound VMs to particular qemu derivations
84+ substituteInPlace src/lxc/lxc_conf.c \
85+ --replace 'lxc_path,' '"/run/libvirt/nix-emulators/libvirt_lxc",'
86+ patchShebangs . # fixes /usr/bin/python references
87+ '';
88+
89+ configureFlags = [
90+ "--localstatedir=/var"
91+ "--sysconfdir=/var/lib"
92+ "--with-libpcap"
93+ "--with-qemu"
94+ "--with-vmware"
95+ "--with-vbox"
96+ "--with-test"
97+ "--with-esx"
98+ "--with-remote"
99+ ] ++ optionals stdenv.isLinux [
100+ "QEMU_BRIDGE_HELPER=/run/wrappers/bin/qemu-bridge-helper"
101+ "QEMU_PR_HELPER=/run/libvirt/nix-helpers/qemu-pr-helper"
102+ "EBTABLES_PATH=${ebtables}/bin/ebtables-legacy"
103+ "--with-attr"
104+ "--with-apparmor"
105+ "--with-secdriver-apparmor"
106+ "--with-numad"
107+ "--with-macvtap"
108+ "--with-virtualport"
109+ "--with-storage-disk"
110+ ] ++ optionals (stdenv.isLinux && zfs != null) [
111+ "--with-storage-zfs"
112+ ] ++ optionals enableIscsi [
113+ "--with-storage-iscsi"
114+ ] ++ optionals enableCeph [
115+ "--with-storage-rbd"
116+ ] ++ optionals stdenv.isDarwin [
117+ "--with-init-script=none"
118+ ];
119+
120+ installFlags = [
121+ "localstatedir=$(TMPDIR)/var"
122+ "sysconfdir=$(out)/var/lib"
123+ ];
124+
125+
126+ postInstall = let
127+ binPath = [ iptables iproute pmutils numad numactl bridge-utils dmidecode dnsmasq ebtables ] ++ optionals enableIscsi [ openiscsi ];
128+ in ''
129+ substituteInPlace $out/libexec/libvirt-guests.sh \
130+ --replace 'ON_BOOT=start' 'ON_BOOT=''${ON_BOOT:-start}' \
131+ --replace 'ON_SHUTDOWN=suspend' 'ON_SHUTDOWN=''${ON_SHUTDOWN:-suspend}' \
132+ --replace "$out/bin" '${gettext}/bin' \
133+ --replace 'lock/subsys' 'lock' \
134+ --replace 'gettext.sh' 'gettext.sh
135+ # Added in nixpkgs:
136+ gettext() { "${gettext}/bin/gettext" "$@"; }
137+ '
138+ '' + optionalString stdenv.isLinux ''
139+ substituteInPlace $out/lib/systemd/system/libvirtd.service --replace /bin/kill ${coreutils}/bin/kill
140+ rm $out/lib/systemd/system/{virtlockd,virtlogd}.*
141+ wrapProgram $out/sbin/libvirtd \
142+ --prefix PATH : /run/libvirt/nix-emulators:${makeBinPath binPath}
143+ '';
144+
145+ enableParallelBuilding = true;
146+
147+ NIX_CFLAGS_COMPILE = "-fno-stack-protector";
148+
149+ meta = {
150+ homepage = http://libvirt.org/;
151+ repositories.git = git://libvirt.org/libvirt.git;
152+ description = ''
153+ A toolkit to interact with the virtualization capabilities of recent
154+ versions of Linux (and other OSes)
155+ '';
156+ license = licenses.lgpl2Plus;
157+ platforms = platforms.unix;
158+ maintainers = with maintainers; [ fpletz globin ];
159+ };
160+}