@@ -0,0 +1,136 @@
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, glib
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.9.0";
21+
22+ src =
23+ if buildFromTarball then
24+ fetchurl {
25+ url = "http://libvirt.org/sources/${pname}-${version}.tar.xz";
26+ sha256 = "0fc9jxw3v6x5hc10bkd7bbcayn24hbld5adj2gh5s648v7hx55il";
27+ }
28+ else
29+ fetchgit {
30+ url = git://libvirt.org/libvirt.git;
31+ rev = "v${version}";
32+ sha256 = "0smm77ag8bg24xkbhl4akqikjrsq2pd3wk31nj0hk1avqnl00gmk";
33+ fetchSubmodules = true;
34+ };
35+
36+ nativeBuildInputs = [ makeWrapper pkgconfig ];
37+ buildInputs = [
38+ libxml2 gnutls perl python2 readline gettext libtasn1 libgcrypt yajl
39+ libxslt xhtml1 perlPackages.XMLXPath curl libpcap glib
40+ ] ++ optionals (!buildFromTarball) [
41+ libtool autoconf automake
42+ ] ++ optionals stdenv.isLinux [
43+ libpciaccess lvm2 utillinux systemd libnl numad zfs
44+ libapparmor libcap_ng numactl attr parted
45+ ] ++ optionals (enableXen && stdenv.isLinux && stdenv.isx86_64) [
46+ xen
47+ ] ++ optionals enableIscsi [
48+ openiscsi
49+ ] ++ optionals enableCeph [
50+ ceph
51+ ] ++ optionals stdenv.isDarwin [
52+ libiconv gmp
53+ ];
54+
55+ preConfigure = ''
56+ ${ optionalString (!buildFromTarball) "./bootstrap --no-git --gnulib-srcdir=$(pwd)/.gnulib" }
57+ PATH=${stdenv.lib.makeBinPath ([ dnsmasq ] ++ optionals stdenv.isLinux [ iproute iptables ebtables lvm2 systemd numad ] ++ optionals enableIscsi [ openiscsi ])}:$PATH
58+ # the path to qemu-kvm will be stored in VM's .xml and .save files
59+ # do not use "''${qemu_kvm}/bin/qemu-kvm" to avoid bound VMs to particular qemu derivations
60+ substituteInPlace src/lxc/lxc_conf.c \
61+ --replace 'lxc_path,' '"/run/libvirt/nix-emulators/libvirt_lxc",'
62+ patchShebangs . # fixes /usr/bin/python references
63+ '';
64+
65+ configureFlags = [
66+ "--localstatedir=/var"
67+ "--sysconfdir=/var/lib"
68+ "--with-libpcap"
69+ "--with-qemu"
70+ "--with-vmware"
71+ "--with-vbox"
72+ "--with-test"
73+ "--with-esx"
74+ "--with-remote"
75+ ] ++ optionals stdenv.isLinux [
76+ "QEMU_BRIDGE_HELPER=/run/wrappers/bin/qemu-bridge-helper"
77+ "QEMU_PR_HELPER=/run/libvirt/nix-helpers/qemu-pr-helper"
78+ "EBTABLES_PATH=${ebtables}/bin/ebtables-legacy"
79+ "--with-attr"
80+ "--with-apparmor"
81+ "--with-secdriver-apparmor"
82+ "--with-numad"
83+ "--with-macvtap"
84+ "--with-virtualport"
85+ "--with-storage-disk"
86+ ] ++ optionals (stdenv.isLinux && zfs != null) [
87+ "--with-storage-zfs"
88+ ] ++ optionals enableIscsi [
89+ "--with-storage-iscsi"
90+ ] ++ optionals enableCeph [
91+ "--with-storage-rbd"
92+ ] ++ optionals stdenv.isDarwin [
93+ "--with-init-script=none"
94+ ];
95+
96+ installFlags = [
97+ "localstatedir=$(TMPDIR)/var"
98+ "sysconfdir=$(out)/var/lib"
99+ ];
100+
101+
102+ postInstall = let
103+ binPath = [ iptables iproute pmutils numad numactl bridge-utils dmidecode dnsmasq ebtables ] ++ optionals enableIscsi [ openiscsi ];
104+ in ''
105+ substituteInPlace $out/libexec/libvirt-guests.sh \
106+ --replace 'ON_BOOT=start' 'ON_BOOT=''${ON_BOOT:-start}' \
107+ --replace 'ON_SHUTDOWN=suspend' 'ON_SHUTDOWN=''${ON_SHUTDOWN:-suspend}' \
108+ --replace "$out/bin" '${gettext}/bin' \
109+ --replace 'lock/subsys' 'lock' \
110+ --replace 'gettext.sh' 'gettext.sh
111+ # Added in nixpkgs:
112+ gettext() { "${gettext}/bin/gettext" "$@"; }
113+ '
114+ '' + optionalString stdenv.isLinux ''
115+ substituteInPlace $out/lib/systemd/system/libvirtd.service --replace /bin/kill ${coreutils}/bin/kill
116+ rm $out/lib/systemd/system/{virtlockd,virtlogd}.*
117+ wrapProgram $out/sbin/libvirtd \
118+ --prefix PATH : /run/libvirt/nix-emulators:${makeBinPath binPath}
119+ '';
120+
121+ enableParallelBuilding = true;
122+
123+ NIX_CFLAGS_COMPILE = "-fno-stack-protector";
124+
125+ meta = {
126+ homepage = http://libvirt.org/;
127+ repositories.git = git://libvirt.org/libvirt.git;
128+ description = ''
129+ A toolkit to interact with the virtualization capabilities of recent
130+ versions of Linux (and other OSes)
131+ '';
132+ license = licenses.lgpl2Plus;
133+ platforms = platforms.unix;
134+ maintainers = with maintainers; [ fpletz globin ];
135+ };
136+}