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:       --replace '$source_path/VERSION' '$source_path/QEMU_VERSION'
      substituteInPlace meson.build \
        --replace "'VERSION'" "'QEMU_VERSION'"
    '' + 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"
      ]
      ++ optional numaSupport "--enable-numa"
      ++ optional seccompSupport "--enable-seccomp"
      ++ optional smartcardSupport "--enable-smartcard"
      ++ optional spiceSupport "--enable-spice"
      ++ optional usbredirSupport "--enable-usb-redir"
      ++ optional (hostCpuTargets != null) "--target-list=${lib.concatStringsSep "," hostCpuTargets}"
      ++ optional stdenv.isDarwin "--enable-cocoa"
      ++ optional stdenv.isDarwin "--enable-hvf"
      ++ optional stdenv.isLinux "--enable-linux-aio"
      ++ optional gtkSupport "--enable-gtk"
      ++ optional xenSupport "--enable-xen"
      ++ optional cephSupport "--enable-rbd"
      ++ optional glusterfsSupport "--enable-glusterfs"
      ++ optional openGLSupport "--enable-opengl"
      ++ optional virglSupport "--enable-virglrenderer"
      ++ optional tpmSupport "--enable-tpm"
      ++ optional libiscsiSupport "--enable-libiscsi"
      ++ optional smbdSupport "--smbd=${samba}/bin/smbd";
  
    doCheck = false; # tries to access /dev
    dontWrapGApps = true;
  
negative.code: , nixosTestRunner ? false
  }:
  
  let
    audio = lib.optionalString alsaSupport "alsa,"
      + lib.optionalString pulseSupport "pa,"
      + lib.optionalString sdlSupport "sdl,";
  
  in
  
  stdenv.mkDerivation rec {
    pname = "qemu"
      + lib.optionalString xenSupport "-xen"
      + lib.optionalString hostCpuOnly "-host-cpu-only"
      + lib.optionalString nixosTestRunner "-for-vm-tests";
    version = "6.0.0";
  
    src = fetchurl {
      url= "https://download.qemu.org/qemu-${version}.tar.xz";
  