anchor.diff:        url = "https://gitlab.com/qemu-project/qemu/-/commit/9f22893adcb02580aee5968f32baa2cd109b3ec2.patch";
         sha256 = "1vkhm9vl671y4cra60b6704339qk1h5dyyb3dfvmvpsvfyh2pm7n";
       })
  -  ] ++ optional nixosTestRunner ./force-uid0-on-9p.patch
  -    ++ optionals stdenv.hostPlatform.isMusl [
  +  ] ++ lib.optional nixosTestRunner ./force-uid0-on-9p.patch
  +    ++ lib.optionals stdenv.hostPlatform.isMusl [
       (fetchpatch {
         url = "https://raw.githubusercontent.com/alpinelinux/aports/2bb133986e8fa90e2e76d53369f03861a87a74ef/main/qemu/xattr_size_max.patch";
         sha256 = "1xfdjs1jlvs99hpf670yianb8c3qz2ars8syzyz8f2c2cp5y4bxb";
  
positive.code: , nixosTestRunner ? false
  }:
  
  with lib;
  let
    audio = optionalString alsaSupport "alsa,"
      + optionalString pulseSupport "pa,"
      + optionalString sdlSupport "sdl,";
  
  in
  
  stdenv.mkDerivation rec {
    version = "6.0.0";
    pname = "qemu"
      + lib.optionalString xenSupport "-xen"
      + lib.optionalString hostCpuOnly "-host-cpu-only"
      + lib.optionalString nixosTestRunner "-for-vm-tests";
  
    src = fetchurl {
      url= "https://download.qemu.org/qemu-${version}.tar.xz";
  
negative.code:       --replace '$source_path/VERSION' '$source_path/QEMU_VERSION'
      substituteInPlace meson.build \
        --replace "'VERSION'" "'QEMU_VERSION'"
    '' + lib.optionalString stdenv.hostPlatform.isMusl ''
      NIX_CFLAGS_COMPILE+=" -D_LINUX_SYSINFO_H"
    '';
  
    configureFlags = [
      "--audio-drv-list=${audio}"
      "--enable-docs"
      "--enable-tools"
      "--enable-guest-agent"
      "--localstatedir=/var"
      "--sysconfdir=/etc"
    ] ++ lib.optional numaSupport "--enable-numa"
      ++ lib.optional seccompSupport "--enable-seccomp"
      ++ lib.optional smartcardSupport "--enable-smartcard"
      ++ lib.optional spiceSupport "--enable-spice"
      ++ lib.optional usbredirSupport "--enable-usb-redir"
      ++ lib.optional (hostCpuTargets != null) "--target-list=${lib.concatStringsSep "," hostCpuTargets}"
      ++ lib.optional stdenv.isDarwin "--enable-cocoa"
      ++ lib.optional stdenv.isDarwin "--enable-hvf"
      ++ lib.optional stdenv.isLinux "--enable-linux-aio"
      ++ lib.optional gtkSupport "--enable-gtk"
      ++ lib.optional xenSupport "--enable-xen"
      ++ lib.optional cephSupport "--enable-rbd"
      ++ lib.optional glusterfsSupport "--enable-glusterfs"
      ++ lib.optional openGLSupport "--enable-opengl"
      ++ lib.optional virglSupport "--enable-virglrenderer"
      ++ lib.optional tpmSupport "--enable-tpm"
      ++ lib.optional libiscsiSupport "--enable-libiscsi"
      ++ lib.optional smbdSupport "--smbd=${samba}/bin/smbd";
  
    doCheck = false; # tries to access /dev
    dontWrapGApps = true;
  