@@ -1,7 +1,7 @@
11{ lib, stdenv, fetchurl, fetchpatch, python, zlib, pkg-config, glib
22, perl, pixman, vde2, alsa-lib, texinfo, flex
33, bison, lzo, snappy, libaio, libtasn1, gnutls, nettle, curl, ninja, meson, sigtool
4−, makeWrapper, autoPatchelfHook
4+, makeWrapper, autoPatchelfHook, runtimeShell
55, attr, libcap, libcap_ng
66, CoreServices, Cocoa, Hypervisor, rez, setfile
77, numaSupport ? stdenv.isLinux && !stdenv.isAarch32, numactl
@@ -228,9 +228,12 @@ stdenv.mkDerivation rec {
228228
229229 # Add a ‘qemu-kvm’ wrapper for compatibility/convenience.
230230 postInstall = ''
231+ cp -- $emitKvmWarningsPath $out/libexec/emit-kvm-warnings
232+ chmod a+x -- $out/libexec/emit-kvm-warnings
231233 if [ -x $out/bin/qemu-system-${stdenv.hostPlatform.qemuArch} ]; then
232234 makeWrapper $out/bin/qemu-system-${stdenv.hostPlatform.qemuArch} \
233235 $out/bin/qemu-kvm \
236+ --run $out/libexec/emit-kvm-warnings \
234237 --add-flags "\$([ -r /dev/kvm -a -w /dev/kvm ] && echo -enable-kvm)"
235238 fi
236239 '';
@@ -242,6 +245,26 @@ stdenv.mkDerivation rec {
242245 # Builds in ~3h with 2 cores, and ~20m with a big-parallel builder.
243246 requiredSystemFeatures = [ "big-parallel" ];
244247
248+ emitKvmWarnings = ''
249+ #!${runtimeShell}
250+ WARNCOL='\033[1;35m'
251+ NEUTRALCOL='\033[0m'
252+ WARNING="''${WARNCOL}warning:''${NEUTRALCOL}"
253+ if [ ! -e /dev/kvm ]; then
254+ echo -e "''${WARNING} KVM is not available - execution will be slow" >&2
255+ echo "Consider installing KVM for hardware-accelerated execution." >&2
256+ echo "If KVM is already installed make sure the kernel module is loaded." >&2
257+ elif [ ! -r /dev/kvm -o ! -w /dev/kvm ]; then
258+ echo -e "''${WARNING} /dev/kvm is not read-/writable - execution will be slow" >&2
259+ echo "/dev/kvm needs to be read-/writable by the user executing QEMU." >&2
260+ echo "" >&2
261+ echo "For hardware-acceleration inside the nix build sandbox /dev/kvm" >&2
262+ echo "must be world-read-/writable (rw-rw-rw-)." >&2
263+ fi
264+ '';
265+
266+ passAsFile = [ "emitKvmWarnings" ];
267+
245268 meta = with lib; {
246269 homepage = "http://www.qemu.org/";
247270 description = "A generic and open source machine emulator and virtualizer";