gnu: qemu: Add OpenGL support.
[jackhill/guix/guix.git] / gnu / packages / virtualization.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2015, 2016, 2017 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2016, 2017 Efraim Flashner <efraim@flashner.co.il>
5 ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
6 ;;; Copyright © 2017 Alex Vong <alexvong1995@gmail.com>
7 ;;; Copyright © 2017 Andy Patterson <ajpatter@uwaterloo.ca>
8 ;;;
9 ;;; This file is part of GNU Guix.
10 ;;;
11 ;;; GNU Guix is free software; you can redistribute it and/or modify it
12 ;;; under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 3 of the License, or (at
14 ;;; your option) any later version.
15 ;;;
16 ;;; GNU Guix is distributed in the hope that it will be useful, but
17 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;;; GNU General Public License for more details.
20 ;;;
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
23
24 (define-module (gnu packages virtualization)
25 #:use-module (gnu packages)
26 #:use-module (gnu packages admin)
27 #:use-module (gnu packages attr)
28 #:use-module (gnu packages autotools)
29 #:use-module (gnu packages check)
30 #:use-module (gnu packages compression)
31 #:use-module (gnu packages curl)
32 #:use-module (gnu packages cyrus-sasl)
33 #:use-module (gnu packages disk)
34 #:use-module (gnu packages dns)
35 #:use-module (gnu packages gl)
36 #:use-module (gnu packages glib)
37 #:use-module (gnu packages gnome)
38 #:use-module (gnu packages gtk)
39 #:use-module (gnu packages image)
40 #:use-module (gnu packages libusb)
41 #:use-module (gnu packages linux)
42 #:use-module (gnu packages ncurses)
43 #:use-module (gnu packages perl)
44 #:use-module (gnu packages pkg-config)
45 #:use-module (gnu packages polkit)
46 #:use-module (gnu packages python)
47 #:use-module (gnu packages selinux)
48 #:use-module (gnu packages sdl)
49 #:use-module (gnu packages spice)
50 #:use-module (gnu packages texinfo)
51 #:use-module (gnu packages tls)
52 #:use-module (gnu packages web)
53 #:use-module (gnu packages xdisorg)
54 #:use-module (gnu packages xml)
55 #:use-module (guix build-system gnu)
56 #:use-module (guix build-system python)
57 #:use-module (guix download)
58 #:use-module ((guix licenses) #:select (gpl2 gpl2+ lgpl2.1+))
59 #:use-module (guix packages)
60 #:use-module (guix utils)
61 #:use-module (srfi srfi-1))
62
63 (define (qemu-patch commit file-name sha256)
64 "Return an origin for COMMIT."
65 (origin
66 (method url-fetch)
67 (uri (string-append
68 "http://git.qemu.org/?p=qemu.git;a=commitdiff_plain;h="
69 commit))
70 (sha256 sha256)
71 (file-name file-name)))
72
73 (define-public qemu
74 (package
75 (name "qemu")
76 (version "2.10.1")
77 (source (origin
78 (method url-fetch)
79 (uri (string-append "https://download.qemu.org/qemu-"
80 version ".tar.xz"))
81 (sha256
82 (base32
83 "1ahwl7r18iw2ds0q3c51nlivqsan9hcgnc8bbf9pv366iy81mm8x"))))
84 (build-system gnu-build-system)
85 (arguments
86 '(;; Running tests in parallel can occasionally lead to failures, like:
87 ;; boot_sector_test: assertion failed (signature == SIGNATURE): (0x00000000 == 0x0000dead)
88 #:parallel-tests? #f
89 #:configure-flags '("--enable-usb-redir" "--enable-opengl")
90 #:phases
91 (modify-phases %standard-phases
92 (replace 'configure
93 (lambda* (#:key inputs outputs (configure-flags '())
94 #:allow-other-keys)
95 ;; The `configure' script doesn't understand some of the
96 ;; GNU options. Thus, add a new phase that's compatible.
97 (let ((out (assoc-ref outputs "out")))
98 (setenv "SHELL" (which "bash"))
99
100 ;; While we're at it, patch for tests.
101 (substitute* "tests/libqtest.c"
102 (("/bin/sh") (which "sh")))
103
104 ;; The binaries need to be linked against -lrt.
105 (setenv "LDFLAGS" "-lrt")
106 (zero?
107 (apply system*
108 `("./configure"
109 ,(string-append "--cc=" (which "gcc"))
110 ;; Some architectures insist on using HOST_CC
111 ,(string-append "--host-cc=" (which "gcc"))
112 "--disable-debug-info" ; save build space
113 "--enable-virtfs" ; just to be sure
114 ,(string-append "--prefix=" out)
115 ,(string-append "--sysconfdir=/etc")
116 ,@configure-flags))))))
117 (add-after 'install 'install-info
118 (lambda* (#:key inputs outputs #:allow-other-keys)
119 ;; Install the Info manual, unless Texinfo is missing.
120 (or (not (assoc-ref inputs "texinfo"))
121 (let ((out (assoc-ref outputs "out")))
122 (and (zero? (system* "make" "info"))
123 (let ((infodir (string-append out "/share/info")))
124 (for-each (lambda (info)
125 (install-file info infodir))
126 (find-files "." "\\.info"))
127 #t))))))
128 (add-before 'check 'make-gtester-verbose
129 (lambda _
130 ;; Make GTester verbose to facilitate investigation upon failure.
131 (setenv "V" "1") #t))
132 (add-before 'check 'disable-test-qga
133 (lambda _
134 (substitute* "tests/Makefile.include"
135 ;; Comment out the test-qga test, which needs /sys and
136 ;; fails within the build environment.
137 (("check-unit-.* tests/test-qga" all)
138 (string-append "# " all)))
139 #t)))))
140 (inputs ; TODO: Add optional inputs.
141 `(("alsa-lib" ,alsa-lib)
142 ("attr" ,attr)
143 ("glib" ,glib)
144 ("libaio" ,libaio)
145 ("libattr" ,attr)
146 ("libcap" ,libcap) ; virtfs support requires libcap & libattr
147 ("libdrm" ,libdrm)
148 ("libepoxy" ,libepoxy)
149 ("libjpeg" ,libjpeg-8)
150 ("libpng" ,libpng)
151 ("libusb" ,libusb) ;USB pass-through support
152 ("mesa" ,mesa)
153 ("ncurses" ,ncurses)
154 ;; ("pciutils" ,pciutils)
155 ("pixman" ,pixman)
156 ("sdl" ,sdl)
157 ("spice" ,spice)
158 ("usbredir" ,usbredir)
159 ("util-linux" ,util-linux)
160 ;; ("vde2" ,vde2)
161 ("virglrenderer" ,virglrenderer)
162 ("zlib" ,zlib)))
163 (native-inputs `(("glib:bin" ,glib "bin") ; gtester, etc.
164 ("perl" ,perl)
165 ("pkg-config" ,pkg-config)
166 ("python" ,python-2) ; incompatible with Python 3 according to error message
167 ("texinfo" ,texinfo)))
168 (home-page "http://www.qemu-project.org")
169 (synopsis "Machine emulator and virtualizer")
170 (description
171 "QEMU is a generic machine emulator and virtualizer.
172
173 When used as a machine emulator, QEMU can run OSes and programs made for one
174 machine (e.g. an ARM board) on a different machine---e.g., your own PC. By
175 using dynamic translation, it achieves very good performance.
176
177 When used as a virtualizer, QEMU achieves near native performances by
178 executing the guest code directly on the host CPU. QEMU supports
179 virtualization when executing under the Xen hypervisor or using
180 the KVM kernel module in Linux. When using KVM, QEMU can virtualize x86,
181 server and embedded PowerPC, and S390 guests.")
182
183 ;; Many files are GPLv2+, but some are GPLv2-only---e.g., `memory.c'.
184 (license gpl2)
185
186 ;; Several tests fail on MIPS; see <http://hydra.gnu.org/build/117914>.
187 (supported-systems (delete "mips64el-linux" %supported-systems))))
188
189 (define-public qemu-minimal
190 ;; QEMU without GUI support.
191 (package (inherit qemu)
192 (name "qemu-minimal")
193 (synopsis "Machine emulator and virtualizer (without GUI)")
194 (arguments
195 (substitute-keyword-arguments (package-arguments qemu)
196 ((#:configure-flags _ '(list))
197 ;; Restrict to the targets supported by Guix.
198 ''("--target-list=i386-softmmu,x86_64-softmmu,mips64el-softmmu,arm-softmmu,aarch64-softmmu"))))
199
200 ;; Remove dependencies on optional libraries, notably GUI libraries.
201 (inputs (fold alist-delete (package-inputs qemu)
202 '("libusb" "mesa" "sdl" "spice" "virglrenderer"
203 "usbredir" "libdrm" "libepoxy")))))
204
205 (define-public libosinfo
206 (package
207 (name "libosinfo")
208 (version "1.0.0")
209 (source
210 (origin
211 (method url-fetch)
212 (uri (string-append "https://releases.pagure.org/libosinfo/libosinfo-"
213 version ".tar.gz"))
214 (sha256
215 (base32
216 "0srrs2m6irqd4f867g8ls6jp2dq3ql0l9d0fh80d55sivvn2bd7p"))))
217 (build-system gnu-build-system)
218 (arguments
219 `(#:configure-flags
220 (list (string-append "--with-usb-ids-path="
221 (assoc-ref %build-inputs "usb.ids"))
222 (string-append "--with-pci-ids-path="
223 (assoc-ref %build-inputs "pci.ids")))
224 #:phases
225 (modify-phases %standard-phases
226 ;; This odd test fails for unknown reasons.
227 (add-after 'unpack 'disable-broken-test
228 (lambda _
229 (substitute* "test/Makefile.in"
230 (("test-isodetect\\$\\(EXEEXT\\)") ""))
231 #t)))))
232 (inputs
233 `(("libsoup" ,libsoup)
234 ("libxml2" ,libxml2)
235 ("libxslt" ,libxslt)
236 ("gobject-introspection" ,gobject-introspection)))
237 (native-inputs
238 `(("check" ,check)
239 ("glib" ,glib "bin") ; glib-mkenums, etc.
240 ("gtk-doc" ,gtk-doc)
241 ("vala" ,vala)
242 ("intltool" ,intltool)
243 ("pkg-config" ,pkg-config)
244 ("pci.ids"
245 ,(origin
246 (method url-fetch)
247 (uri "https://github.com/pciutils/pciids/raw/ad02084f0bc143e3c15e31a6152a3dfb1d7a3156/pci.ids")
248 (sha256
249 (base32
250 "0kfhpj5rnh24hz2714qhfmxk281vwc2w50sm73ggw5d15af7zfsw"))))
251 ("usb.ids"
252 ,(origin
253 (method url-fetch)
254 (uri "http://linux-usb.cvs.sourceforge.net/viewvc/linux-usb/htdocs/usb.ids?revision=1.551")
255 (file-name "usb.ids")
256 (sha256
257 (base32
258 "17rg5i0wbyk289gr8v4kgvnc9q5bidz7ldcvv9x58l083wn16hq3"))))))
259 (home-page "https://libosinfo.org/")
260 (synopsis "Operating system information database")
261 (description "libosinfo is a GObject based library API for managing
262 information about operating systems, hypervisors and the (virtual) hardware
263 devices they can support. It includes a database containing device metadata
264 and provides APIs to match/identify optimal devices for deploying an operating
265 system on a hypervisor. Via GObject Introspection, the API is available in
266 all common programming languages. Vala bindings are also provided.")
267 ;; The library files are released under LGPLv2.1 or later; the source
268 ;; files in the "tools" directory are released under GPLv2+.
269 (license (list lgpl2.1+ gpl2+))))
270
271 (define-public lxc
272 (package
273 (name "lxc")
274 (version "2.0.8")
275 (source (origin
276 (method url-fetch)
277 (uri (string-append
278 "https://linuxcontainers.org/downloads/lxc/lxc-"
279 version ".tar.gz"))
280 (sha256
281 (base32
282 "15449r56rqg3487kzsnfvz0w4p5ajrq0krcsdh6c9r6g0ark93hd"))))
283 (build-system gnu-build-system)
284 (native-inputs
285 `(("pkg-config" ,pkg-config)))
286 (inputs
287 `(("gnutls" ,gnutls)
288 ("libcap" ,libcap)
289 ("libseccomp" ,libseccomp)
290 ("libselinux" ,libselinux)))
291 (arguments
292 '(#:configure-flags
293 '("--sysconfdir=/etc"
294 "--localstatedir=/var")
295 #:phases
296 (modify-phases %standard-phases
297 (replace 'install
298 (lambda* (#:key outputs #:allow-other-keys)
299 (let* ((out (assoc-ref outputs "out"))
300 (bashcompdir (string-append out "/etc/bash_completion.d")))
301 (zero? (system*
302 "make" "install"
303 (string-append "bashcompdir=" bashcompdir)
304 ;; Don't install files into /var and /etc.
305 "LXCPATH=/tmp/var/lib/lxc"
306 "localstatedir=/tmp/var"
307 "sysconfdir=/tmp/etc"
308 "sysconfigdir=/tmp/etc/default"))))))))
309 (synopsis "Linux container tools")
310 (home-page "https://linuxcontainers.org/")
311 (description
312 "LXC is a userspace interface for the Linux kernel containment features.
313 Through a powerful API and simple tools, it lets Linux users easily create and
314 manage system or application containers.")
315 (license lgpl2.1+)))
316
317 (define-public libvirt
318 (package
319 (name "libvirt")
320 (version "3.7.0")
321 (source (origin
322 (method url-fetch)
323 (uri (string-append "https://libvirt.org/sources/libvirt-"
324 version ".tar.xz"))
325 (sha256
326 (base32
327 "1fk75cdzg59y9hnfdpdwv83fsc1yffy3lac4ch19zygfkqhcnysf"))))
328 (build-system gnu-build-system)
329 (arguments
330 `(;; FAIL: virshtest
331 ;; FAIL: virfirewalltest
332 ;; FAIL: virkmodtest
333 ;; FAIL: virnetsockettest
334 ;; FAIL: networkxml2firewalltest
335 ;; FAIL: nwfilterebiptablestest
336 ;; FAIL: nwfilterxml2firewalltest
337 ;; Times while running commandest.
338 #:tests? #f
339 #:configure-flags
340 (list "--with-polkit"
341 "--sysconfdir=/etc"
342 "--localstatedir=/var")
343 #:phases
344 (modify-phases %standard-phases
345 (add-after 'unpack 'fix-tests
346 (lambda _
347 (substitute* '("tests/commandtest.c"
348 "gnulib/tests/test-posix_spawn1.c"
349 "gnulib/tests/test-posix_spawn2.c")
350 (("/bin/sh") (which "sh")))
351 #t))
352 (replace 'install
353 ;; Since the sysconfdir and localstatedir should be /etc and /var
354 ;; at runtime, we must prevent writing to them at installation
355 ;; time.
356 (lambda _
357 (zero? (system* "make" "install"
358 "sysconfdir=/tmp/etc"
359 "localstatedir=/tmp/var"))))
360 (add-after 'install 'wrap-libvirtd
361 (lambda* (#:key inputs outputs #:allow-other-keys)
362 (let ((out (assoc-ref outputs "out")))
363 (wrap-program (string-append out "/sbin/libvirtd")
364 `("PATH" = (,(string-append (assoc-ref inputs "iproute")
365 "/sbin")
366 ,(string-append (assoc-ref inputs "qemu")
367 "/bin"))))
368 #t))))))
369 (inputs
370 `(("libxml2" ,libxml2)
371 ("gnutls" ,gnutls)
372 ("dbus" ,dbus)
373 ("qemu" ,qemu)
374 ("libpcap" ,libpcap)
375 ("libnl" ,libnl)
376 ("libuuid" ,util-linux)
377 ("lvm2" ,lvm2) ; for libdevmapper
378 ("curl" ,curl)
379 ("openssl" ,openssl)
380 ("cyrus-sasl" ,cyrus-sasl)
381 ("libyajl" ,libyajl)
382 ("audit" ,audit)
383 ("dmidecode" ,dmidecode)
384 ("dnsmasq" ,dnsmasq)
385 ("ebtables" ,ebtables)
386 ("iproute" ,iproute)
387 ("iptables" ,iptables)))
388 (native-inputs
389 `(("xsltproc" ,libxslt)
390 ("perl" ,perl)
391 ("pkg-config" ,pkg-config)
392 ("polkit" ,polkit)
393 ("python" ,python-2)))
394 (home-page "https://libvirt.org")
395 (synopsis "Simple API for virtualization")
396 (description "Libvirt is a C toolkit to interact with the virtualization
397 capabilities of recent versions of Linux. The library aims at providing long
398 term stable C API initially for the Xen paravirtualization but should be able
399 to integrate other virtualization mechanisms if needed.")
400 (license lgpl2.1+)))
401
402 (define-public libvirt-glib
403 (package
404 (name "libvirt-glib")
405 (version "1.0.0")
406 (source (origin
407 (method url-fetch)
408 (uri (string-append "ftp://libvirt.org/libvirt/glib/"
409 "libvirt-glib-" version ".tar.gz"))
410 (sha256
411 (base32
412 "0iwa5sdbii52pjpdm5j37f67sdmf0kpcky4liwhy1nf43k85i4fa"))))
413 (build-system gnu-build-system)
414 (arguments
415 `(#:phases
416 (modify-phases %standard-phases
417 (add-after 'unpack 'fix-tests
418 (lambda _
419 (substitute* "tests/test-events.c"
420 (("/bin/true") (which "true")))
421 #t)))))
422 (inputs
423 `(("libxml2" ,libxml2)
424 ("libvirt" ,libvirt)
425 ("gobject-introspection" ,gobject-introspection)
426 ("glib" ,glib)
427 ("openssl" ,openssl)
428 ("cyrus-sasl" ,cyrus-sasl)
429 ("lvm2" ,lvm2) ; for libdevmapper
430 ("libyajl" ,libyajl)))
431 (native-inputs
432 `(("pkg-config" ,pkg-config)
433 ("intltool" ,intltool)
434 ("glib" ,glib "bin")
435 ("vala" ,vala)))
436 (home-page "https://libvirt.org")
437 (synopsis "GLib wrapper around libvirt")
438 (description "libvirt-glib wraps the libvirt library to provide a
439 high-level object-oriented API better suited for glib-based applications, via
440 three libraries:
441
442 @enumerate
443 @item libvirt-glib - GLib main loop integration & misc helper APIs
444 @item libvirt-gconfig - GObjects for manipulating libvirt XML documents
445 @item libvirt-gobject - GObjects for managing libvirt objects
446 @end enumerate
447 ")
448 (license lgpl2.1+)))
449
450 (define-public python-libvirt
451 (package
452 (name "python-libvirt")
453 (version "3.7.0")
454 (source (origin
455 (method url-fetch)
456 (uri (pypi-uri "libvirt-python" version))
457 (sha256
458 (base32
459 "0vy0ai8z88yhzqfk1n08z1gda5flrqxcw9lg1012b3zg125qljhy"))))
460 (build-system python-build-system)
461 (arguments
462 `(#:phases
463 (modify-phases %standard-phases
464 (add-after 'unpack 'patch-nosetests-path
465 (lambda* (#:key inputs #:allow-other-keys)
466 (substitute* "setup.py"
467 (("\"/usr/bin/nosetests\"")
468 (string-append "\"" (which "nosetests") "\""))
469 (("self\\.spawn\\(\\[sys\\.executable, nose\\]\\)")
470 (format #f "self.spawn([\"~a\", nose])" (which "bash"))))
471 #t)))))
472 (inputs
473 `(("libvirt" ,libvirt)))
474 (propagated-inputs
475 `(("python-lxml" ,python-lxml)))
476 (native-inputs
477 `(("pkg-config" ,pkg-config)
478 ("python-nose" ,python-nose)))
479 (home-page "https://libvirt.org")
480 (synopsis "Python bindings to libvirt")
481 (description "This package provides Python bindings to the libvirt
482 virtualization library.")
483 (license lgpl2.1+)))
484
485 (define-public python2-libvirt
486 (package-with-python2 python-libvirt))
487
488 (define-public virt-manager
489 (package
490 (name "virt-manager")
491 (version "1.4.3")
492 (source (origin
493 (method url-fetch)
494 (uri (string-append "https://virt-manager.org/download/sources"
495 "/virt-manager/virt-manager-"
496 version ".tar.gz"))
497 (sha256
498 (base32
499 "093azs8p4p7y4nf5j25xpsvdxww7gky1g0hs8mkcvmpxl2wjd0jj"))))
500 (build-system python-build-system)
501 (arguments
502 `(#:python ,python-2
503 #:use-setuptools? #f ; Uses custom distutils 'install' command.
504 ;; Some of the tests seem to require network access to install virtual
505 ;; machines.
506 #:tests? #f
507 #:modules ((ice-9 match)
508 (srfi srfi-26)
509 (guix build python-build-system)
510 (guix build utils))
511 #:phases
512 (modify-phases %standard-phases
513 (add-after 'unpack 'fix-setup
514 (lambda* (#:key outputs #:allow-other-keys)
515 (substitute* "virtcli/cliconfig.py"
516 (("/usr") (assoc-ref outputs "out")))
517 #t))
518 (add-before 'wrap 'wrap-with-GI_TYPELIB_PATH
519 (lambda* (#:key inputs outputs #:allow-other-keys)
520 (let* ((bin (string-append (assoc-ref outputs "out") "/bin"))
521 (bin-files (find-files bin ".*"))
522 (paths (map (match-lambda
523 ((output . directory)
524 (let* ((girepodir (string-append
525 directory
526 "/lib/girepository-1.0")))
527 (if (file-exists? girepodir)
528 girepodir #f))))
529 inputs)))
530 (for-each (lambda (file)
531 (format #t "wrapping ~a\n" file)
532 (wrap-program file
533 `("GI_TYPELIB_PATH" ":" prefix
534 ,(filter identity paths))))
535 bin-files))
536 #t)))))
537 (inputs
538 `(("gtk+" ,gtk+)
539 ("gtk-vnc" ,gtk-vnc)
540 ("libvirt" ,libvirt)
541 ("libvirt-glib" ,libvirt-glib)
542 ("libosinfo" ,libosinfo)
543 ("vte" ,vte)
544 ("gobject-introspection" ,gobject-introspection)
545 ("python2-libvirt" ,python2-libvirt)
546 ("python2-requests" ,python2-requests)
547 ("python2-ipaddr" ,python2-ipaddr)
548 ("python2-pygobject" ,python2-pygobject)
549 ("python2-libxml2" ,python2-libxml2)
550 ("spice-gtk" ,spice-gtk)))
551 ;; virt-manager searches for qemu-img or kvm-img in the PATH.
552 (propagated-inputs
553 `(("qemu" ,qemu)))
554 (native-inputs
555 `(("glib" ,glib "bin") ; glib-compile-schemas.
556 ("gtk+" ,gtk+ "bin") ; gtk-update-icon-cache
557 ("perl" ,perl) ; pod2man
558 ("intltool" ,intltool)))
559 (home-page "https://virt-manager.org/")
560 (synopsis "Manage virtual machines")
561 (description
562 "The virt-manager application is a desktop user interface for managing
563 virtual machines through libvirt. It primarily targets KVM VMs, but also
564 manages Xen and LXC (Linux containers). It presents a summary view of running
565 domains, their live performance and resource utilization statistics.")
566 (license gpl2+)))