xen_4_8: init at 4.8.1

This commit adds the xen_4_8 package to be used instead of
xen (currently at 4.5.5):
* Add packages xen_4_8, xen_4_8-slim and xen_4_8-light
* Add packages qemu_xen_4_8 and qemu_xen_4_8-light to be used
with xen_4_8-slim and xen_4_8-light respectively.
* Add systemd to buildInputs of xen (it is required by oxenstored)
* Adapt xen service to work with the new version of xen
* Use xen-init-dom0 to initlilise dom0 in xen-store
* Currently, the virtualisation.xen.stored option is ignored
if xen 4.8 is used

+270 -28
+35 -20
nixos/modules/virtualisation/xen-dom0.nix
··· 267 mkdir -p /var/lib/xen # so we create them here unconditionally. 268 grep -q control_d /proc/xen/capabilities 269 ''; 270 - serviceConfig.ExecStart = '' 271 - ${cfg.stored}${optionalString cfg.trace " -T /var/log/xen/xenstored-trace.log"} --no-fork 272 - ''; 273 postStart = '' 274 - time=0 275 - timeout=30 276 - # Wait for xenstored to actually come up, timing out after 30 seconds 277 - while [ $time -lt $timeout ] && ! `${cfg.package}/bin/xenstore-read -s / >/dev/null 2>&1` ; do 278 - time=$(($time+1)) 279 - sleep 1 280 - done 281 - 282 - # Exit if we timed out 283 - if ! [ $time -lt $timeout ] ; then 284 - echo "Could not start Xenstore Daemon" 285 - exit 1 286 - fi 287 288 - ${cfg.package}/bin/xenstore-write "/local/domain/0/name" "Domain-0" 289 - ${cfg.package}/bin/xenstore-write "/local/domain/0/domid" 0 290 ''; 291 }; 292 ··· 306 description = "Xen Console Daemon"; 307 wantedBy = [ "multi-user.target" ]; 308 after = [ "xen-store.service" ]; 309 preStart = '' 310 mkdir -p /var/run/xen 311 ${optionalString cfg.trace "mkdir -p /var/log/xen"} ··· 313 ''; 314 serviceConfig = { 315 ExecStart = '' 316 - ${cfg.package}/bin/xenconsoled${optionalString cfg.trace " --log=all --log-dir=/var/log/xen"} 317 ''; 318 }; 319 }; ··· 323 description = "Xen Qemu Daemon"; 324 wantedBy = [ "multi-user.target" ]; 325 after = [ "xen-console.service" ]; 326 serviceConfig.ExecStart = '' 327 ${cfg.qemu} -xen-attach -xen-domid 0 -name dom0 -M xenpv \ 328 -nographic -monitor /dev/null -serial /dev/null -parallel /dev/null ··· 333 systemd.services.xen-watchdog = { 334 description = "Xen Watchdog Daemon"; 335 wantedBy = [ "multi-user.target" ]; 336 - after = [ "xen-qemu.service" ]; 337 serviceConfig.ExecStart = "${cfg.package}/bin/xenwatchdogd 30 15"; 338 serviceConfig.Type = "forking"; 339 serviceConfig.RestartSec = "1"; ··· 426 description = "Xen domains - automatically starts, saves and restores Xen domains"; 427 wantedBy = [ "multi-user.target" ]; 428 after = [ "xen-bridge.service" "xen-qemu.service" ]; 429 ## To prevent a race between dhcpcd and xend's bridge setup script 430 ## (which renames eth* to peth* and recreates eth* as a virtual 431 ## device), start dhcpcd after xend.
··· 267 mkdir -p /var/lib/xen # so we create them here unconditionally. 268 grep -q control_d /proc/xen/capabilities 269 ''; 270 + serviceConfig = if cfg.package.version < "4.8" then 271 + { ExecStart = '' 272 + ${cfg.stored}${optionalString cfg.trace " -T /var/log/xen/xenstored-trace.log"} --no-fork 273 + ''; 274 + } else { 275 + ExecStart = '' 276 + ${cfg.package}/etc/xen/scripts/launch-xenstore 277 + ''; 278 + Type = "notify"; 279 + RemainAfterExit = true; 280 + NotifyAccess = "all"; 281 + }; 282 postStart = '' 283 + ${optionalString (cfg.package.version < "4.8") '' 284 + time=0 285 + timeout=30 286 + # Wait for xenstored to actually come up, timing out after 30 seconds 287 + while [ $time -lt $timeout ] && ! `${cfg.package}/bin/xenstore-read -s / >/dev/null 2>&1` ; do 288 + time=$(($time+1)) 289 + sleep 1 290 + done 291 292 + # Exit if we timed out 293 + if ! [ $time -lt $timeout ] ; then 294 + echo "Could not start Xenstore Daemon" 295 + exit 1 296 + fi 297 + ''} 298 + echo "executing xen-init-dom0" 299 + ${cfg.package}/lib/xen/bin/xen-init-dom0 300 ''; 301 }; 302 ··· 316 description = "Xen Console Daemon"; 317 wantedBy = [ "multi-user.target" ]; 318 after = [ "xen-store.service" ]; 319 + requires = [ "xen-store.service" ]; 320 preStart = '' 321 mkdir -p /var/run/xen 322 ${optionalString cfg.trace "mkdir -p /var/log/xen"} ··· 324 ''; 325 serviceConfig = { 326 ExecStart = '' 327 + ${cfg.package}/bin/xenconsoled\ 328 + ${optionalString ((cfg.package.version >= "4.8")) " -i"}\ 329 + ${optionalString cfg.trace " --log=all --log-dir=/var/log/xen"} 330 ''; 331 }; 332 }; ··· 336 description = "Xen Qemu Daemon"; 337 wantedBy = [ "multi-user.target" ]; 338 after = [ "xen-console.service" ]; 339 + requires = [ "xen-store.service" ]; 340 serviceConfig.ExecStart = '' 341 ${cfg.qemu} -xen-attach -xen-domid 0 -name dom0 -M xenpv \ 342 -nographic -monitor /dev/null -serial /dev/null -parallel /dev/null ··· 347 systemd.services.xen-watchdog = { 348 description = "Xen Watchdog Daemon"; 349 wantedBy = [ "multi-user.target" ]; 350 + after = [ "xen-qemu.service" "xen-domains.service" ]; 351 serviceConfig.ExecStart = "${cfg.package}/bin/xenwatchdogd 30 15"; 352 serviceConfig.Type = "forking"; 353 serviceConfig.RestartSec = "1"; ··· 440 description = "Xen domains - automatically starts, saves and restores Xen domains"; 441 wantedBy = [ "multi-user.target" ]; 442 after = [ "xen-bridge.service" "xen-qemu.service" ]; 443 + requires = [ "xen-bridge.service" "xen-qemu.service" ]; 444 ## To prevent a race between dhcpcd and xend's bridge setup script 445 ## (which renames eth* to peth* and recreates eth* as a virtual 446 ## device), start dhcpcd after xend.
+165
pkgs/applications/virtualization/xen/4.8.nix
···
··· 1 + { stdenv, callPackage, fetchurl, fetchpatch, fetchgit 2 + , withInternalQemu ? true 3 + , withInternalTraditionalQemu ? true 4 + , withInternalSeabios ? true 5 + , withSeabios ? !withInternalSeabios, seabios ? null 6 + , withInternalOVMF ? false # FIXME: tricky to build 7 + , withOVMF ? false, OVMF 8 + , withLibHVM ? true 9 + 10 + # qemu 11 + , udev, pciutils, xorg, SDL, pixman, acl, glusterfs, spice_protocol, usbredir 12 + , alsaLib 13 + , ... } @ args: 14 + 15 + assert withInternalSeabios -> !withSeabios; 16 + assert withInternalOVMF -> !withOVMF; 17 + 18 + with stdenv.lib; 19 + 20 + # Patching XEN? Check the XSAs at 21 + # https://xenbits.xen.org/xsa/ 22 + # and try applying all the ones we don't have yet. 23 + 24 + let 25 + xsaPatch = { name , sha256 }: (fetchpatch { 26 + url = "https://xenbits.xen.org/xsa/xsa${name}.patch"; 27 + inherit sha256; 28 + }); 29 + 30 + qemuDeps = [ 31 + udev pciutils xorg.libX11 SDL pixman acl glusterfs spice_protocol usbredir 32 + alsaLib 33 + ]; 34 + in 35 + 36 + callPackage (import ./generic.nix (rec { 37 + version = "4.8.1"; 38 + 39 + src = fetchurl { 40 + url = "http://bits.xensource.com/oss-xen/release/${version}/xen-${version}.tar.gz"; 41 + sha256 = "158kb1w61jmwxi3fc560s4269hhpxrin9xhm60ljj52njhxias8x"; 42 + }; 43 + 44 + # Sources needed to build tools and firmwares. 45 + xenfiles = optionalAttrs withInternalQemu { 46 + "qemu-xen" = { 47 + src = fetchgit { 48 + url = https://xenbits.xen.org/git-http/qemu-xen.git; 49 + rev = "refs/tags/qemu-xen-${version}"; 50 + sha256 = "1v19pp86kcgwvsbkrdrn4rlaj02i4054avw8k70w1m0rnwgcsdbs"; 51 + }; 52 + buildInputs = qemuDeps; 53 + patches = [ 54 + #(xsaPatch { 55 + # name = "197-4.5-qemuu"; 56 + # sha256 = "09gp980qdlfpfmxy0nk7ncyaa024jnrpzx9gpq2kah21xygy5myx"; 57 + #}) 58 + ]; 59 + meta.description = "Xen's fork of upstream Qemu"; 60 + }; 61 + } // optionalAttrs withInternalTraditionalQemu { 62 + "qemu-xen-traditional" = { 63 + src = fetchgit { 64 + url = https://xenbits.xen.org/git-http/qemu-xen-traditional.git; 65 + rev = "refs/tags/xen-${version}"; 66 + sha256 = "0mryap5y53r09m7qc0b821f717ghwm654r8c3ik1w7adzxr0l5qk"; 67 + }; 68 + buildInputs = qemuDeps; 69 + patches = [ 70 + ]; 71 + postPatch = '' 72 + substituteInPlace xen-hooks.mak \ 73 + --replace /usr/include/pci ${pciutils}/include/pci 74 + ''; 75 + meta.description = "Xen's fork of upstream Qemu that uses old device model"; 76 + }; 77 + } // optionalAttrs withInternalSeabios { 78 + "firmware/seabios-dir-remote" = { 79 + src = fetchgit { 80 + url = https://xenbits.xen.org/git-http/seabios.git; 81 + rev = "f0cdc36d2f2424f6b40438f7ee7cc502c0eff4df"; 82 + sha256 = "1wq5pjkjrfzqnq3wyr15mcn1l4c563m65gdyf8jm97kgb13pwwfm"; 83 + }; 84 + patches = [ ./0000-qemu-seabios-enable-ATA_DMA.patch ]; 85 + meta.description = "Xen's fork of Seabios"; 86 + }; 87 + } // optionalAttrs withInternalOVMF { 88 + "firmware/ovmf-dir-remote" = { 89 + src = fetchgit { 90 + url = https://xenbits.xen.org/git-http/ovmf.git; 91 + rev = "173bf5c847e3ca8b42c11796ce048d8e2e916ff8"; 92 + sha256 = "07zmdj90zjrzip74fvd4ss8n8njk6cim85s58mc6snxmqqv7gmcr"; 93 + }; 94 + meta.description = "Xen's fork of OVMF"; 95 + }; 96 + } // { 97 + # TODO: patch Xen to make this optional? 98 + "firmware/etherboot/ipxe.git" = { 99 + src = fetchgit { 100 + url = https://git.ipxe.org/ipxe.git; 101 + rev = "356f6c1b64d7a97746d1816cef8ca22bdd8d0b5d"; 102 + sha256 = "15n400vm3id5r8y3k6lrp9ab2911a9vh9856f5gvphkazfnmns09"; 103 + }; 104 + meta.description = "Xen's fork of iPXE"; 105 + }; 106 + } // optionalAttrs withLibHVM { 107 + "xen-libhvm-dir-remote" = { 108 + src = fetchgit { 109 + name = "xen-libhvm"; 110 + url = https://github.com/michalpalka/xen-libhvm; 111 + rev = "83065d36b36d6d527c2a4e0f5aaf0a09ee83122c"; 112 + sha256 = "1jzv479wvgjkazprqdzcdjy199azmx2xl3pnxli39kc5mvjz3lzd"; 113 + }; 114 + buildPhase = '' 115 + make 116 + cd biospt 117 + cc -Wall -g -D_LINUX -Wstrict-prototypes biospt.c -o biospt -I../libhvm -L../libhvm -lxenhvm 118 + ''; 119 + installPhase = '' 120 + make install 121 + cp biospt/biospt $out/bin/ 122 + ''; 123 + meta = { 124 + description = '' 125 + Helper library for reading ACPI and SMBIOS firmware values 126 + from the host system for use with the HVM guest firmware 127 + pass-through feature in Xen''; 128 + license = licenses.bsd2; 129 + }; 130 + }; 131 + }; 132 + 133 + configureFlags = [] 134 + ++ optional (!withInternalQemu) "--with-system-qemu" # use qemu from PATH 135 + ++ optional (withInternalTraditionalQemu) "--enable-qemu-traditional" 136 + ++ optional (!withInternalTraditionalQemu) "--disable-qemu-traditional" 137 + 138 + ++ optional (withSeabios) "--with-system-seabios=${seabios}" 139 + ++ optional (!withInternalSeabios && !withSeabios) "--disable-seabios" 140 + 141 + ++ optional (withOVMF) "--with-system-ovmf=${OVMF.fd}/FV/OVMF.fd" 142 + ++ optional (withInternalOVMF) "--enable-ovmf"; 143 + 144 + patches = 145 + [ (xsaPatch { 146 + name = "213-4.8"; 147 + sha256 = "0ia3zr6r3bqy2h48fdy7p0iz423lniy3i0qkdvzgv5a8m80darr2"; 148 + }) 149 + (xsaPatch { 150 + name = "214"; 151 + sha256 = "0qapzx63z0yl84phnpnglpkxp6b9sy1y7cilhwjhxyigpfnm2rrk"; 152 + }) 153 + ]; 154 + 155 + # Fix build on Glibc 2.24. 156 + NIX_CFLAGS_COMPILE = "-Wno-error=deprecated-declarations"; 157 + 158 + postPatch = '' 159 + # Avoid a glibc >= 2.25 deprecation warnings that get fatal via -Werror. 160 + sed 1i'#include <sys/sysmacros.h>' \ 161 + -i tools/blktap2/control/tap-ctl-allocate.c \ 162 + -i tools/libxl/libxl_device.c 163 + ''; 164 + 165 + })) args
+15 -8
pkgs/applications/virtualization/xen/generic.nix
··· 14 # Scripts 15 , coreutils, gawk, gnused, gnugrep, diffutils, multipath-tools 16 , iproute, inetutils, iptables, bridge-utils, openvswitch, nbd, drbd 17 - , lvm2, utillinux, procps 18 19 # Documentation 20 # python2Packages.markdown ··· 61 libiconv libuuid ncurses openssl perl python2Packages.python xz yajl zlib 62 63 # oxenstored 64 - ocamlPackages.findlib ocamlPackages.ocaml 65 66 # Python fixes 67 python2Packages.wrapPython ··· 153 substituteInPlace tools/xenstat/Makefile \ 154 --replace /usr/include/curses.h ${ncurses.dev}/include/curses.h 155 156 - # TODO: use this as a template and support our own if-up scripts instead? 157 - substituteInPlace tools/hotplug/Linux/xen-backend.rules.in \ 158 - --replace "@XEN_SCRIPT_DIR@" $out/etc/xen/scripts 159 160 - # blktap is not provided by xen, but by xapi 161 - sed -i '/blktap/d' tools/hotplug/Linux/xen-backend.rules.in 162 163 ${withTools "patches" (name: x: '' 164 ${concatMapStringsSep "\n" (p: '' ··· 191 ''; 192 193 installPhase = '' 194 - mkdir -p $out $out/share 195 cp -prvd dist/install/nix/store/*/* $out/ 196 cp -prvd dist/install/boot $out/boot 197 cp -prvd dist/install/etc $out
··· 14 # Scripts 15 , coreutils, gawk, gnused, gnugrep, diffutils, multipath-tools 16 , iproute, inetutils, iptables, bridge-utils, openvswitch, nbd, drbd 17 + , lvm2, utillinux, procps, systemd 18 19 # Documentation 20 # python2Packages.markdown ··· 61 libiconv libuuid ncurses openssl perl python2Packages.python xz yajl zlib 62 63 # oxenstored 64 + ocamlPackages.findlib ocamlPackages.ocaml systemd 65 66 # Python fixes 67 python2Packages.wrapPython ··· 153 substituteInPlace tools/xenstat/Makefile \ 154 --replace /usr/include/curses.h ${ncurses.dev}/include/curses.h 155 156 + ${optionalString (config.version >= "4.8") '' 157 + substituteInPlace tools/hotplug/Linux/launch-xenstore.in \ 158 + --replace /bin/mkdir mkdir 159 + ''} 160 + 161 + ${optionalString (config.version < "4.6") '' 162 + # TODO: use this as a template and support our own if-up scripts instead? 163 + substituteInPlace tools/hotplug/Linux/xen-backend.rules.in \ 164 + --replace "@XEN_SCRIPT_DIR@" $out/etc/xen/scripts 165 166 + # blktap is not provided by xen, but by xapi 167 + sed -i '/blktap/d' tools/hotplug/Linux/xen-backend.rules.in 168 + ''} 169 170 ${withTools "patches" (name: x: '' 171 ${concatMapStringsSep "\n" (p: '' ··· 198 ''; 199 200 installPhase = '' 201 + mkdir -p $out $out/share $out/share/man 202 cp -prvd dist/install/nix/store/*/* $out/ 203 cp -prvd dist/install/boot $out/boot 204 cp -prvd dist/install/etc $out
+50
pkgs/applications/virtualization/xen/packages.nix
··· 57 }; 58 }; 59 60 xen-vanilla = xen_4_5-vanilla; 61 xen-slim = xen_4_5-slim; 62 xen-light = xen_4_5-light;
··· 57 }; 58 }; 59 60 + xen_4_8-vanilla = callPackage ./4.8.nix { 61 + # At the very least included seabios and etherboot need gcc49, 62 + # so we have to build all of it with gcc49. 63 + stdenv = overrideCC stdenv gcc49; 64 + 65 + meta = { 66 + description = "vanilla"; 67 + longDescription = '' 68 + Vanilla version of Xen. Uses forks of Qemu and Seabios bundled 69 + with Xen. This gives vanilla experince, but wastes space and 70 + build time: typical NixOS setup that runs lots of VMs will 71 + build three different versions of Qemu when using this (two 72 + forks and upstream). 73 + ''; 74 + }; 75 + }; 76 + 77 + xen_4_8-slim = xen_4_8-vanilla.override { 78 + withInternalQemu = false; 79 + withInternalTraditionalQemu = true; 80 + withInternalSeabios = false; 81 + withSeabios = true; 82 + 83 + meta = { 84 + description = "slim"; 85 + longDescription = '' 86 + Slimmed-down version of Xen that reuses nixpkgs packages as 87 + much as possible. Different parts may get out of sync, but 88 + this builds faster and uses less space than vanilla. Use with 89 + `qemu_xen` from nixpkgs. 90 + ''; 91 + }; 92 + }; 93 + 94 + xen_4_8-light = xen_4_8-vanilla.override { 95 + withInternalQemu = false; 96 + withInternalTraditionalQemu = false; 97 + withInternalSeabios = false; 98 + withSeabios = true; 99 + 100 + meta = { 101 + description = "light"; 102 + longDescription = '' 103 + Slimmed-down version of Xen without `qemu-traditional` (you 104 + don't need it if you don't know what it is). Use with 105 + `qemu_xen-light` from nixpkgs. 106 + ''; 107 + }; 108 + }; 109 + 110 xen-vanilla = xen_4_5-vanilla; 111 xen-slim = xen_4_5-slim; 112 xen-light = xen_4_5-light;
+5
pkgs/top-level/all-packages.nix
··· 12352 # Building with `xen` instead of `xen-slim` is possible, but makes no sense. 12353 qemu_xen = lowPrio (qemu.override { x86Only = true; xenSupport = true; xen = xen-slim; }); 12354 qemu_xen-light = lowPrio (qemu.override { x86Only = true; xenSupport = true; xen = xen-light; }); 12355 12356 qemu_test = lowPrio (qemu.override { x86Only = true; nixosTestRunner = true; }); 12357 ··· 16631 xen = xenPackages.xen_4_5-vanilla; 16632 xen-slim = xenPackages.xen_4_5-slim; 16633 xen-light = xenPackages.xen_4_5-light; 16634 16635 xkbset = callPackage ../tools/X11/xkbset { }; 16636
··· 12352 # Building with `xen` instead of `xen-slim` is possible, but makes no sense. 12353 qemu_xen = lowPrio (qemu.override { x86Only = true; xenSupport = true; xen = xen-slim; }); 12354 qemu_xen-light = lowPrio (qemu.override { x86Only = true; xenSupport = true; xen = xen-light; }); 12355 + qemu_xen_4_8 = lowPrio (qemu.override { x86Only = true; xenSupport = true; xen = xen_4_8-slim; }); 12356 + qemu_xen_4_8-light = lowPrio (qemu.override { x86Only = true; xenSupport = true; xen = xen_4_8-light; }); 12357 12358 qemu_test = lowPrio (qemu.override { x86Only = true; nixosTestRunner = true; }); 12359 ··· 16633 xen = xenPackages.xen_4_5-vanilla; 16634 xen-slim = xenPackages.xen_4_5-slim; 16635 xen-light = xenPackages.xen_4_5-light; 16636 + xen_4_8 = xenPackages.xen_4_8-vanilla; 16637 + xen_4_8-slim = xenPackages.xen_4_8-slim; 16638 + xen_4_8-light = xenPackages.xen_4_8-light; 16639 16640 xkbset = callPackage ../tools/X11/xkbset { }; 16641