nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ stdenv, fetchurl, fetchgit
2, pkgconfig, makeWrapper, libtool, autoconf, automake
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
13with 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>
16let
17 buildFromTarball = stdenv.isDarwin;
18in stdenv.mkDerivation rec {
19 name = "libvirt-${version}";
20 version = "4.10.0";
21
22 src =
23 if buildFromTarball then
24 fetchurl {
25 url = "http://libvirt.org/sources/${name}.tar.xz";
26 sha256 = "0v17zzyyb25nn9l18v5244myg7590dp6ppwgi8xysipifc0q77bz";
27 }
28 else
29 fetchgit {
30 url = git://libvirt.org/libvirt.git;
31 rev = "v${version}";
32 sha256 = "0dlpv3v6jpbmgvhpn29ryp0w2a1xny8ciqid8hnlf3klahz9kwz9";
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
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
58 PATH=${stdenv.lib.makeBinPath ([ dnsmasq ] ++ optionals stdenv.isLinux [ iproute iptables ebtables lvm2 systemd numad ] ++ optionals enableIscsi [ openiscsi ])}:$PATH
59
60 # the path to qemu-kvm will be stored in VM's .xml and .save files
61 # do not use "''${qemu_kvm}/bin/qemu-kvm" to avoid bound VMs to particular qemu derivations
62 substituteInPlace src/lxc/lxc_conf.c \
63 --replace 'lxc_path,' '"/run/libvirt/nix-emulators/libvirt_lxc",'
64
65 patchShebangs . # fixes /usr/bin/python references
66 '';
67
68 configureFlags = [
69 "--localstatedir=/var"
70 "--sysconfdir=/var/lib"
71 "--with-libpcap"
72 "--with-qemu"
73 "--with-vmware"
74 "--with-vbox"
75 "--with-test"
76 "--with-esx"
77 "--with-remote"
78 ] ++ optionals stdenv.isLinux [
79 "--with-attr"
80 "--with-apparmor"
81 "--with-secdriver-apparmor"
82 "--with-numad"
83 "--with-macvtap"
84 "--with-virtualport"
85 "--with-init-script=systemd+redhat"
86 "--with-storage-disk"
87 ] ++ optionals (stdenv.isLinux && zfs != null) [
88 "--with-storage-zfs"
89 ] ++ optionals enableIscsi [
90 "--with-storage-iscsi"
91 ] ++ optionals enableCeph [
92 "--with-storage-rbd"
93 ] ++ optionals stdenv.isDarwin [
94 "--with-init-script=none"
95 ];
96
97 installFlags = [
98 "localstatedir=$(TMPDIR)/var"
99 "sysconfdir=$(out)/var/lib"
100 ];
101
102
103 postInstall = let
104 binPath = [ iptables iproute pmutils numad numactl bridge-utils dmidecode dnsmasq ebtables ] ++ optionals enableIscsi [ openiscsi ];
105 in ''
106 substituteInPlace $out/libexec/libvirt-guests.sh \
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 ];
135 };
136}