@ -1,230 +1,70 @@
{ stdenv , fetchurl , pkgconfig , libtool , python , perl , texinfo , flex , bison
, gettext , makeWrapper , glib , zlib , pixman
# Optional Arguments
, SDL2 ? null , gtk ? null , gnutls ? null , cyrus_sasl ? null , libjpeg ? null
, libpng ? null , ncurses ? null , curl ? null , libcap ? null , attr ? null
, bluez ? null , libibverbs ? null , librdmacm ? null , libuuid ? null , vde2 ? null
, libaio ? null , libcap_ng ? null , spice ? null , spice_protocol ? null
, libceph ? null , libxfs ? null , nss ? null , nspr ? null , libusb ? null
, usbredir ? null , mesa ? null , lzo ? null , snappy ? null , bzip2 ? null
, libseccomp ? null , glusterfs ? null , libssh2 ? null , numactl ? null
# Audio libraries
, libpulseaudio ? null , alsaLib ? null
# Extra options
, type ? " "
{ stdenv , fetchurl , python , zlib , pkgconfig , glib , ncurses , perl , pixman
, attr , libcap , vde2 , alsaLib , texinfo , libuuid , flex , bison , lzo , snappy
, libseccomp , libaio , libcap_ng , gnutls
, makeWrapper
, pulseSupport ? true , libpulseaudio
, sdlSupport ? true , SDL
, vncSupport ? true , libjpeg , libpng
, spiceSupport ? true , spice , spice_protocol , usbredir
, x86Only ? false
} :
with stdenv . lib ;
let
n = " q e m u - 2 . 3 . 0 " ;
mkFlag = trueStr : falseStr : cond : name : val :
if cond == null then null else
" - - ${ if cond != false then trueStr else falseStr } ${ name } ${ if val != null && cond != false then " = ${ val } " else " " } " ;
mkEnable = mkFlag " e n a b l e - " " d i s a b l e - " ;
mkWith = mkFlag " w i t h - " " w i t h o u t - " ;
mkOther = mkFlag " " " " true ;
shouldUsePkg = pkg : if pkg != null && stdenv . lib . any ( x : x == stdenv . system ) pkg . meta . platforms then pkg else null ;
optSDL2 = if type == " n i x " then null else shouldUsePkg SDL2 ;
optGtk = if type == " n i x " then null else shouldUsePkg gtk ;
optLibcap = if type == " n i x " then null else shouldUsePkg libcap ;
optAttr = if type == " n i x " then null else shouldUsePkg attr ;
optGnutls = if type == " n i x " then null else shouldUsePkg gnutls ;
optCyrus_sasl = if type == " n i x " then null else shouldUsePkg cyrus_sasl ;
optLibjpeg = if type == " n i x " then null else shouldUsePkg libjpeg ;
optLibpng = if type == " n i x " then null else shouldUsePkg libpng ;
optNcurses = if type == " n i x " then null else shouldUsePkg ncurses ;
optCurl = if type == " n i x " then null else shouldUsePkg curl ;
optBluez = if type == " n i x " then null else shouldUsePkg bluez ;
optLibibverbs = if type == " n i x " then null else shouldUsePkg libibverbs ;
optLibrdmacm = if type == " n i x " then null else shouldUsePkg librdmacm ;
optLibuuid = if type == " n i x " then null else shouldUsePkg libuuid ;
optVde2 = if type == " n i x " then null else shouldUsePkg vde2 ;
optLibaio = shouldUsePkg libaio ;
optLibcap_ng = shouldUsePkg libcap_ng ;
optSpice = if type == " n i x " then null else shouldUsePkg spice ;
optSpice_protocol = if type == " n i x " then null else shouldUsePkg spice_protocol ;
optLibceph = if type == " n i x " then null else shouldUsePkg libceph ;
optLibxfs = if type == " n i x " then null else shouldUsePkg libxfs ;
optNss = if type == " n i x " then null else shouldUsePkg nss ;
optNspr = if type == " n i x " then null else shouldUsePkg nspr ;
optLibusb = if type == " n i x " then null else shouldUsePkg libusb ;
optUsbredir = if type == " n i x " then null else shouldUsePkg usbredir ;
optMesa = if type == " n i x " then null else shouldUsePkg mesa ;
optLzo = if type == " n i x " then null else shouldUsePkg lzo ;
optSnappy = if type == " n i x " then null else shouldUsePkg snappy ;
optBzip2 = if type == " n i x " then null else shouldUsePkg bzip2 ;
optLibseccomp = if type == " n i x " then null else shouldUsePkg libseccomp ;
optGlusterfs = if type == " n i x " then null else shouldUsePkg glusterfs ;
optLibssh2 = if type == " n i x " then null else shouldUsePkg libssh2 ;
optNumactl = if type == " n i x " then null else shouldUsePkg numactl ;
hasSDLAbi = if optSDL2 != null then true else null ;
hasVirtfs = stdenv . isLinux && optLibcap != null && optAttr != null ;
hasVnc = type != " n i x " ;
hasVncTls = hasVnc && optGnutls != null ;
hasVncSasl = hasVnc && optCyrus_sasl != null ;
hasVncJpeg = hasVnc && optLibjpeg != null ;
hasVncPng = hasVnc && optLibpng != null ;
hasVncWs = hasVnc && optGnutls != null ;
hasFdt = type != " n i x " ;
hasRdma = optLibibverbs != null && optLibrdmacm != null ;
hasLinuxAio = stdenv . isLinux && optLibaio != null ;
hasSpice = optSpice != null && optSpice_protocol != null ;
hasNss = optNss != null && optNspr != null ;
optLibpulseaudio = if type == " n i x " then null else shouldUsePkg libpulseaudio ;
optAlsaLib = if type == " n i x " then null else shouldUsePkg alsaLib ;
audio = concatStringsSep " , " (
optional ( optSDL2 != null ) " s d l "
++ optional ( optLibpulseaudio != null ) " p a "
++ optional ( optAlsaLib != null ) " a l s a "
) ;
systemBinary = if stdenv . system == " x 8 6 _ 6 4 - l i n u x " then " x 8 6 _ 6 4 "
else if stdenv . system == " i 6 8 6 - l i n u x " then " i 3 8 6 "
else null ;
targetList = if stdenv . system == " x 8 6 _ 6 4 - l i n u x " then " x 8 6 _ 6 4 - s o f t m m u , i 3 8 6 - s o f t m m u "
else if stdenv . system == " i 6 8 6 - l i n u x " then " i 3 8 6 - s o f t m m u "
else null ;
n = " q e m u - 2 . 2 . 1 " ;
audio = optionalString ( hasSuffix " l i n u x " stdenv . system ) " a l s a , "
+ optionalString pulseSupport " p a , "
+ optionalString sdlSupport " s d l , " ;
in
stdenv . mkDerivation rec {
name = " ${ n } ${ optionalString ( type != null && type != " " ) " - ${ type } " } " ;
name = n + ( if x86Only then " - x 8 6 - o n l y " else " " ) ;
src = fetchurl {
url = " h t t p : / / w i k i . q e m u . o r g / d o w n l o a d / ${ n } . t a r . b z 2 " ;
sha256 = " 1 20 m 5 3 c 3 p 2 8 q x m f z l l i c j z r 8 s y j v 6 v 4 d 9 r s y r g k p 7 g n m c g v v g f m n " ;
sha256 = " 1 8 1 m 2 d d s g 3 a d w 8 y 5 d m i m s i 8 x 6 7 8 i m n 9 f 6 i 5 p 2 0 z b h i 7 p d r 6 1 a 5 s 6 " ;
} ;
nativeBuildInputs = [ pkgconfig libtool perl texinfo flex bison gettext makeWrapper ] ;
buildInputs = [
python glib zlib pixman optSDL2 optGtk optNcurses optCurl optBluez optVde2
optLibcap_ng optAttr optLibuuid optLibceph optLibxfs optLibusb optUsbredir
optMesa optLzo optSnappy optBzip2 optLibseccomp optGlusterfs optLibssh2
optNumactl optLibpulseaudio optAlsaLib
] ++ optionals ( hasVncTls || hasVncWs ) [
optGnutls
] ++ optionals hasVncSasl [
optCyrus_sasl
] ++ optionals hasVncJpeg [
optLibjpeg
] ++ optionals hasVncPng [
optLibpng
] ++ optionals hasVirtfs [
optLibcap
] ++ optionals hasRdma [
optLibibverbs optLibrdmacm
] ++ optionals hasLinuxAio [
optLibaio
] ++ optionals hasSpice [
optSpice optSpice_protocol
] ++ optionals hasNss [
optNss optNspr
] ;
buildInputs =
[ python zlib pkgconfig glib ncurses perl pixman attr libcap
vde2 texinfo libuuid flex bison makeWrapper lzo snappy libseccomp
libcap_ng gnutls
]
++ optionals pulseSupport [ libpulseaudio ]
++ optionals sdlSupport [ SDL ]
++ optionals vncSupport [ libjpeg libpng ]
++ optionals spiceSupport [ spice_protocol spice usbredir ]
++ optionals ( hasSuffix " l i n u x " stdenv . system ) [ alsaLib libaio ] ;
enableParallelBuilding = true ;
configureFlags = [
( mkOther " s m b d " " s m b d " )
( mkOther " s y s c o n f d i r " " / e t c " )
( mkOther " l o c a l s t a t e d i r " " / v a r " )
( mkEnable true " m o d u l e s " null )
( mkEnable false " d e b u g - t c g " null )
( mkEnable false " d e b u g - i n f o " null )
( mkEnable false " s p a r s e " null )
( mkEnable false " w e r r o r " null )
( mkEnable ( optSDL2 != null ) " s d l " null )
( mkWith hasSDLAbi " s d l a b i " " 2 . 0 " )
( mkEnable ( optGtk != null ) " g t k " null )
( mkEnable hasVirtfs " v i r t f s " null )
( mkEnable hasVnc " v n c " null )
( mkEnable stdenv . isDarwin " c o c o a " null )
( mkOther " a u d i o - d r v - l i s t " audio )
( mkEnable false " x e n " null )
( mkEnable false " x e n - p c i - p a s s t h r o u g h " null )
( mkEnable false " b r l a p i " null )
( mkEnable hasVncTls " v n c - t l s " null )
( mkEnable hasVncSasl " v n c - s a s l " null )
( mkEnable hasVncJpeg " v n c - j p e g " null )
( mkEnable hasVncPng " v n c - p n g " null )
( mkEnable hasVncWs " v n c - w s " null )
( mkEnable ( optNcurses != null ) " c u r s e s " null )
( mkEnable ( optCurl != null ) " c u r l " null )
( mkEnable hasFdt " f d t " null )
( mkEnable ( optBluez != null ) " b l u e z " null )
( mkEnable stdenv . isLinux " k v m " null )
( mkEnable hasRdma " r d m a " null )
( mkEnable ( type != " n i x " ) " s y s t e m " null )
( mkEnable ( type != " k v m - o n l y " ) " u s e r " null )
( mkEnable ( type != " k v m - o n l y " ) " g u e s t - b a s e " null )
( mkEnable true " p i e " null )
( mkEnable ( optLibuuid != null ) " u u i d " null )
( mkEnable ( optVde2 != null ) " v d e " null )
( mkEnable false " n e t m a p " null ) # TODO(wkennington): Add Support
( mkEnable hasLinuxAio " l i n u x - a i o " null )
( mkEnable ( optLibcap_ng != null ) " c a p - n g " null )
( mkEnable ( optAttr != null ) " a t t r " null )
( mkEnable ( type != " n i x " ) " d o c s " null )
( mkEnable stdenv . isLinux " v h o s t - n e t " null )
( mkEnable hasSpice " s p i c e " null )
( mkEnable ( optLibceph != null ) " r b d " null )
( mkEnable false " l i b i s c s i " null ) # TODO(wkennington): Add support
( mkEnable false " l i b n f s " null ) # TODO(wkennington): Add support
( mkEnable ( optLibxfs != null ) " x f s c t l " null )
( mkEnable hasNss " s m a r t c a r d - n s s " null )
( mkEnable ( optLibusb != null ) " l i b u s b " null )
( mkEnable ( optUsbredir != null ) " u s b - r e d i r " null )
( mkEnable ( optMesa != null ) " o p e n g l " null )
( mkEnable ( optLzo != null ) " l z o " null )
( mkEnable ( optSnappy != null ) " s n a p p y " null )
( mkEnable ( optBzip2 != null ) " b z i p 2 " null )
( mkEnable true " g u e s t - a g e n t " null )
( mkEnable ( optLibseccomp != null ) " s e c c o m p " null )
( mkEnable ( optGlusterfs != null ) " g l u s t e r f s " null )
( mkEnable false " a r c h i p e l a g o " null )
( mkEnable true " t p m " null )
( mkEnable ( optLibssh2 != null ) " l i b s s h 2 " null )
( mkEnable ( optLibuuid != null ) " v h d x " null )
( mkEnable ( optGnutls != null ) " q u o r u m " null )
( mkEnable ( optNumactl != null ) " n u m a " null )
] ++ optionals ( type == " k v m - o n l y " ) [
( mkOther " t a r g e t - l i s t " targetList )
] ;
patches = [ ./no-etc-install.patch ] ;
installFlags = [
" s y s c o n f d i r = \$ { o u t } / e t c "
" q e m u _ c o n f d i r = \$ { o u t } / e t c / q e m u "
" q e m u _ l o c a l s t a t e d i r = \$ { T M P D I R } "
] ;
configureFlags =
[ " - - e n a b l e - s e c c o m p "
" - - s m b d = s m b d " # use `smbd' from $PATH
" - - a u d i o - d r v - l i s t = ${ audio } "
" - - s y s c o n f d i r = / e t c "
" - - l o c a l s t a t e d i r = / v a r "
]
++ optional spiceSupport " - - e n a b l e - s p i c e "
++ optional x86Only " - - t a r g e t - l i s t = i 3 8 6 - s o f t m m u , x 8 6 _ 6 4 - s o f t m m u "
++ optional ( hasSuffix " l i n u x " stdenv . system ) " - - e n a b l e - l i n u x - a i o " ;
postInstall = optionalString ( systemBinary != null ) ''
# Add a ‘ qemu-kvm’ wrapper for compatibility/convenience.
p = " $ o u t / b i n / q e m u - s y s t e m - ${ systemBinary } "
if [ - e " $ p " ] ; then
makeWrapper " $ p " $ out/bin/qemu-kvm - - add-flags " \$ ( [ - e / d e v / k v m ] & & e c h o - e n a b l e - k v m ) "
fi
'' ;
postInstall =
''
# Add a ‘ qemu-kvm’ wrapper for compatibility/convenience.
p = " $ o u t / b i n / q e m u - s y s t e m - ${ if stdenv . system == " x 8 6 _ 6 4 - l i n u x " then " x 8 6 _ 6 4 " else " i 3 8 6 " } "
if [ - e " $ p " ] ; then
makeWrapper " $ p " $ out/bin/qemu-kvm - - add-flags " \$ ( [ - e / d e v / k v m ] & & e c h o - e n a b l e - k v m ) "
fi
'' ;
meta = with stdenv . lib ; {
homepage = http://www.qemu.org/ ;
description = " A g e n e r i c a n d o p e n s o u r c e m a c h i n e e m u l a t o r a n d v i r t u a l i z e r " ;
license = licenses . gpl2Plus ;
maintainers = with maintainers ; [ viric shlevy eelco wkennington ] ;
platforms = if type == " k v m - o n l y " then platforms . linux else platforms . all ;
maintainers = with maintainers ; [ viric shlevy eelco ] ;
platforms = platforms . linux ;
} ;
}