@@ -1,70 +1,240 @@
1−{ stdenv, fetchurl, python, zlib, pkgconfig, glib, ncurses, perl, pixman
2−, attr, libcap, vde2, alsaLib, texinfo, libuuid, flex, bison, lzo, snappy
3−, libseccomp, libaio, libcap_ng, gnutls
4−, makeWrapper
5−, pulseSupport ? true, pulseaudio
6−, sdlSupport ? true, SDL
7−, vncSupport ? true, libjpeg, libpng
8−, spiceSupport ? true, spice, spice_protocol, usbredir
9−, x86Only ? false
1+{ stdenv, fetchurl, pkgconfig, libtool, python, perl, texinfo, flex, bison
2+, gettext, makeWrapper, glib, zlib, pixman
3+
4+# Optional Arguments
5+, SDL2 ? null, gtk ? null, gnutls ? null, cyrus_sasl ? null, libjpeg ? null
6+, libpng ? null, ncurses ? null, curl ? null, libcap ? null, attr ? null
7+, bluez ? null, libibverbs ? null, librdmacm ? null, libuuid ? null, vde2 ? null
8+, libaio ? null, libcap_ng ? null, spice ? null, spice_protocol ? null
9+, libceph ? null, libxfs ? null, nss ? null, nspr ? null, libusb ? null
10+, usbredir ? null, mesa ? null, lzo ? null, snappy ? null, bzip2 ? null
11+, libseccomp ? null, glusterfs ? null, libssh2 ? null, numactl ? null
12+
13+# Audio libraries
14+, libpulseaudio ? null, alsaLib ? null
15+
16+#, pixman ? null
17+#, python, zlib, glib, ncurses, perl
18+#, attr, libcap, vde2, alsaLib, texinfo, libuuid, flex, bison, lzo, snappy
19+#, libseccomp, libaio, libcap_ng, gnutls
20+#, makeWrapper
21+#, pulseSupport ? true, pulseaudio
22+#, sdlSupport ? true, SDL
23+#, vncSupport ? true, libjpeg, libpng
24+#, spiceSupport ? true, spice, spice_protocol, usbredir
25+
26+# Extra options
27+, type ? ""
1028}:
1129
1230with stdenv.lib;
1331let
14− n = "qemu-2.2.1";
15− audio = optionalString (hasSuffix "linux" stdenv.system) "alsa,"
16− + optionalString pulseSupport "pa,"
17− + optionalString sdlSupport "sdl,";
32+ n = "qemu-2.3.0";
33+
34+ mkFlag = trueStr: falseStr: cond: name: val:
35+ if cond == null then null else
36+ "--${if cond != false then trueStr else falseStr}${name}${if val != null && cond != false then "=${val}" else ""}";
37+ mkEnable = mkFlag "enable-" "disable-";
38+ mkWith = mkFlag "with-" "without-";
39+ mkOther = mkFlag "" "" true;
40+
41+ shouldUsePkg = pkg: if pkg != null && stdenv.lib.any (x: x == stdenv.system) pkg.meta.platforms then pkg else null;
42+
43+ optSDL2 = if type == "nix" then null else shouldUsePkg SDL2;
44+ optGtk = if type == "nix" then null else shouldUsePkg gtk;
45+ optLibcap = if type == "nix" then null else shouldUsePkg libcap;
46+ optAttr = if type == "nix" then null else shouldUsePkg attr;
47+ optGnutls = if type == "nix" then null else shouldUsePkg gnutls;
48+ optCyrus_sasl = if type == "nix" then null else shouldUsePkg cyrus_sasl;
49+ optLibjpeg = if type == "nix" then null else shouldUsePkg libjpeg;
50+ optLibpng = if type == "nix" then null else shouldUsePkg libpng;
51+ optNcurses = if type == "nix" then null else shouldUsePkg ncurses;
52+ optCurl = if type == "nix" then null else shouldUsePkg curl;
53+ optBluez = if type == "nix" then null else shouldUsePkg bluez;
54+ optLibibverbs = if type == "nix" then null else shouldUsePkg libibverbs;
55+ optLibrdmacm = if type == "nix" then null else shouldUsePkg librdmacm;
56+ optLibuuid = if type == "nix" then null else shouldUsePkg libuuid;
57+ optVde2 = if type == "nix" then null else shouldUsePkg vde2;
58+ optLibaio = shouldUsePkg libaio;
59+ optLibcap_ng = shouldUsePkg libcap_ng;
60+ optSpice = if type == "nix" then null else shouldUsePkg spice;
61+ optSpice_protocol = if type == "nix" then null else shouldUsePkg spice_protocol;
62+ optLibceph = if type == "nix" then null else shouldUsePkg libceph;
63+ optLibxfs = if type == "nix" then null else shouldUsePkg libxfs;
64+ optNss = if type == "nix" then null else shouldUsePkg nss;
65+ optNspr = if type == "nix" then null else shouldUsePkg nspr;
66+ optLibusb = if type == "nix" then null else shouldUsePkg libusb;
67+ optUsbredir = if type == "nix" then null else shouldUsePkg usbredir;
68+ optMesa = if type == "nix" then null else shouldUsePkg mesa;
69+ optLzo = if type == "nix" then null else shouldUsePkg lzo;
70+ optSnappy = if type == "nix" then null else shouldUsePkg snappy;
71+ optBzip2 = if type == "nix" then null else shouldUsePkg bzip2;
72+ optLibseccomp = if type == "nix" then null else shouldUsePkg libseccomp;
73+ optGlusterfs = if type == "nix" then null else shouldUsePkg glusterfs;
74+ optLibssh2 = if type == "nix" then null else shouldUsePkg libssh2;
75+ optNumactl = if type == "nix" then null else shouldUsePkg numactl;
76+
77+ hasSDLAbi = if optSDL2 != null then true else null;
78+
79+ hasVirtfs = stdenv.isLinux && optLibcap != null && optAttr != null;
80+
81+ hasVnc = type != "nix";
82+ hasVncTls = hasVnc && optGnutls != null;
83+ hasVncSasl = hasVnc && optCyrus_sasl != null;
84+ hasVncJpeg = hasVnc && optLibjpeg != null;
85+ hasVncPng = hasVnc && optLibpng != null;
86+ hasVncWs = hasVnc && optGnutls != null;
87+
88+ hasFdt = type != "nix";
89+
90+ hasRdma = optLibibverbs != null && optLibrdmacm != null;
91+
92+ hasLinuxAio = stdenv.isLinux && optLibaio != null;
93+
94+ hasSpice = optSpice != null && optSpice_protocol != null;
95+
96+ hasNss = optNss != null && optNspr != null;
97+
98+ optLibpulseaudio = if type == "nix" then null else shouldUsePkg libpulseaudio;
99+ optAlsaLib = if type == "nix" then null else shouldUsePkg alsaLib;
100+ audio = concatStringsSep "," (
101+ optional (optSDL2 != null) "sdl"
102+ ++ optional (optLibpulseaudio != null) "pa"
103+ ++ optional (optAlsaLib != null) "alsa"
104+ );
105+
106+ systemBinary = if stdenv.system == "x86_64-linux" then "x86_64"
107+ else if stdenv.system == "i686-linux" then "i386"
108+ else null;
109+
110+ targetList = if stdenv.system == "x86_64-linux" then "x86_64-softmmu,i386-softmmu"
111+ else if stdenv.system == "i686-linux" then "i386-softmmu"
112+ else null;
18113in
19114
20115stdenv.mkDerivation rec {
21− name = n + (if x86Only then "-x86-only" else "");
116+ name = "${n}${optionalString (type != null && type != "") "-${type}"}";
22117
23118 src = fetchurl {
24119 url = "http://wiki.qemu.org/download/${n}.tar.bz2";
25− sha256 = "181m2ddsg3adw8y5dmimsi8x678imn9f6i5p20zbhi7pdr61a5s6";
120+ sha256 = "120m53c3p28qxmfzllicjzr8syjv6v4d9rsyrgkp7gnmcgvvgfmn";
26121 };
27122
28− buildInputs =
29− [ python zlib pkgconfig glib ncurses perl pixman attr libcap
30− vde2 texinfo libuuid flex bison makeWrapper lzo snappy libseccomp
31− libcap_ng gnutls
32− ]
33− ++ optionals pulseSupport [ pulseaudio ]
34− ++ optionals sdlSupport [ SDL ]
35− ++ optionals vncSupport [ libjpeg libpng ]
36− ++ optionals spiceSupport [ spice_protocol spice usbredir ]
37− ++ optionals (hasSuffix "linux" stdenv.system) [ alsaLib libaio ];
123+ nativeBuildInputs = [ pkgconfig libtool perl texinfo flex bison gettext makeWrapper ];
124+
125+ buildInputs = [
126+ python glib zlib pixman optSDL2 optGtk optNcurses optCurl optBluez optVde2
127+ optLibcap_ng optAttr optLibuuid optLibceph optLibxfs optLibusb optUsbredir
128+ optMesa optLzo optSnappy optBzip2 optLibseccomp optGlusterfs optLibssh2
129+ optNumactl optLibpulseaudio optAlsaLib
130+ ] ++ optionals (hasVncTls || hasVncWs) [
131+ optGnutls
132+ ] ++ optionals hasVncSasl [
133+ optCyrus_sasl
134+ ] ++ optionals hasVncJpeg [
135+ optLibjpeg
136+ ] ++ optionals hasVncPng [
137+ optLibpng
138+ ] ++ optionals hasVirtfs [
139+ optLibcap
140+ ] ++ optionals hasRdma [
141+ optLibibverbs optLibrdmacm
142+ ] ++ optionals hasLinuxAio [
143+ optLibaio
144+ ] ++ optionals hasSpice [
145+ optSpice optSpice_protocol
146+ ] ++ optionals hasNss [
147+ optNss optNspr
148+ ];
38149
39150 enableParallelBuilding = true;
40151
41− patches = [ ./no-etc-install.patch ];
42−
43− configureFlags =
44− [ "--enable-seccomp"
45− "--smbd=smbd" # use `smbd' from $PATH
46− "--audio-drv-list=${audio}"
47− "--sysconfdir=/etc"
48− "--localstatedir=/var"
49− ]
50− ++ optional spiceSupport "--enable-spice"
51− ++ optional x86Only "--target-list=i386-softmmu,x86_64-softmmu"
52− ++ optional (hasSuffix "linux" stdenv.system) "--enable-linux-aio";
53−
54− postInstall =
55− ''
56− # Add a ‘qemu-kvm’ wrapper for compatibility/convenience.
57− p="$out/bin/qemu-system-${if stdenv.system == "x86_64-linux" then "x86_64" else "i386"}"
58− if [ -e "$p" ]; then
59− makeWrapper "$p" $out/bin/qemu-kvm --add-flags "\$([ -e /dev/kvm ] && echo -enable-kvm)"
60− fi
61− '';
152+ configureFlags = [
153+ (mkOther "smbd" "smbd")
154+ (mkOther "sysconfdir" "/etc")
155+ (mkOther "localstatedir" "/var")
156+ (mkEnable true "modules" null)
157+ (mkEnable false "debug-tcg" null)
158+ (mkEnable false "debug-info" null)
159+ (mkEnable false "sparse" null)
160+ (mkEnable false "werror" null)
161+ (mkEnable (optSDL2 != null) "sdl" null)
162+ (mkWith hasSDLAbi "sdlabi" "2.0")
163+ (mkEnable (optGtk != null) "gtk" null)
164+ (mkEnable hasVirtfs "virtfs" null)
165+ (mkEnable hasVnc "vnc" null)
166+ (mkEnable stdenv.isDarwin "cocoa" null)
167+ (mkOther "audio-drv-list" audio)
168+ (mkEnable false "xen" null)
169+ (mkEnable false "xen-pci-passthrough" null)
170+ (mkEnable false "brlapi" null)
171+ (mkEnable hasVncTls "vnc-tls" null)
172+ (mkEnable hasVncSasl "vnc-sasl" null)
173+ (mkEnable hasVncJpeg "vnc-jpeg" null)
174+ (mkEnable hasVncPng "vnc-png" null)
175+ (mkEnable hasVncWs "vnc-ws" null)
176+ (mkEnable (optNcurses != null) "curses" null)
177+ (mkEnable (optCurl != null) "curl" null)
178+ (mkEnable hasFdt "fdt" null)
179+ (mkEnable (optBluez != null) "bluez" null)
180+ (mkEnable stdenv.isLinux "kvm" null)
181+ (mkEnable hasRdma "rdma" null)
182+ (mkEnable (type != "nix") "system" null)
183+ (mkEnable (type != "kvm-only") "user" null)
184+ (mkEnable (type != "kvm-only") "guest-base" null)
185+ (mkEnable true "pie" null)
186+ (mkEnable (optLibuuid != null) "uuid" null)
187+ (mkEnable (optVde2 != null) "vde" null)
188+ (mkEnable false "netmap" null) # TODO(wkennington): Add Support
189+ (mkEnable hasLinuxAio "linux-aio" null)
190+ (mkEnable (optLibcap_ng != null) "cap-ng" null)
191+ (mkEnable (optAttr != null) "attr" null)
192+ (mkEnable (type != "nix") "docs" null)
193+ (mkEnable stdenv.isLinux "vhost-net" null)
194+ (mkEnable hasSpice "spice" null)
195+ (mkEnable (optLibceph != null) "rbd" null)
196+ (mkEnable false "libiscsi" null) # TODO(wkennington): Add support
197+ (mkEnable false "libnfs" null) # TODO(wkennington): Add support
198+ (mkEnable (optLibxfs != null) "xfsctl" null)
199+ (mkEnable hasNss "smartcard-nss" null)
200+ (mkEnable (optLibusb != null) "libusb" null)
201+ (mkEnable (optUsbredir != null) "usb-redir" null)
202+ (mkEnable (optMesa != null) "opengl" null)
203+ (mkEnable (optLzo != null) "lzo" null)
204+ (mkEnable (optSnappy != null) "snappy" null)
205+ (mkEnable (optBzip2 != null) "bzip2" null)
206+ (mkEnable true "guest-agent" null)
207+ (mkEnable (optLibseccomp != null) "seccomp" null)
208+ (mkEnable (optGlusterfs != null) "glusterfs" null)
209+ (mkEnable false "archipelago" null)
210+ (mkEnable true "tpm" null)
211+ (mkEnable (optLibssh2 != null) "libssh2" null)
212+ (mkEnable (optLibuuid != null) "vhdx" null)
213+ (mkEnable (optGnutls != null) "quorum" null)
214+ (mkEnable (optNumactl != null) "numa" null)
215+ ] ++ optionals (type == "kvm-only") [
216+ (mkOther "target-list" targetList)
217+ ];
218+
219+ installFlags = [
220+ "sysconfdir=\${out}/etc"
221+ "qemu_confdir=\${out}/etc/qemu"
222+ "qemu_localstatedir=\${TMPDIR}"
223+ ];
224+
225+ postInstall = optionalString (systemBinary != null) ''
226+ # Add a ‘qemu-kvm’ wrapper for compatibility/convenience.
227+ p="$out/bin/qemu-system-${systemBinary}"
228+ if [ -e "$p" ]; then
229+ makeWrapper "$p" $out/bin/qemu-kvm --add-flags "\$([ -e /dev/kvm ] && echo -enable-kvm)"
230+ fi
231+ '';
62232
63233 meta = with stdenv.lib; {
64234 homepage = http://www.qemu.org/;
65235 description = "A generic and open source machine emulator and virtualizer";
66236 license = licenses.gpl2Plus;
67− maintainers = with maintainers; [ viric shlevy eelco ];
68− platforms = platforms.linux;
237+ maintainers = with maintainers; [ viric shlevy eelco wkennington ];
238+ platforms = if type == "kvm-only" then platforms.linux else platforms.all;
69239 };
70240}