anchor.diff:              ''
                 mkdir $out
                 diskImage=$out/disk.img
  -              bootFlash=$out/bios.bin
                 ${qemu}/bin/qemu-img create -f qcow2 $diskImage "40M"
                 ${if cfg.useEFIBoot then ''
  -                cp ${pkgs.OVMF-CSM.fd}/FV/OVMF.fd $bootFlash
  -                chmod 0644 $bootFlash
  +                efiVars=$out/EFI_VARS.fd
  +                cp ${efiVars} $efiVars
  +                chmod 0644 $efiVars
                 '' else ''
                 ''}
               '';
             buildInputs = [ pkgs.utillinux ];
  -          QEMU_OPTS = if cfg.useEFIBoot
  -                      then "-pflash $out/bios.bin -nographic -serial pty"
  -                      else "-nographic -serial pty";
  +          QEMU_OPTS = "-nographic -serial stdio -monitor none"
  +                      + lib.optionalString cfg.useEFIBoot (
  +                        " -drive if=pflash,format=raw,unit=0,readonly=on,file=${efiFirmware}"
  +                      + " -drive if=pflash,format=raw,unit=1,file=$efiVars");
           }
           ''
             # Create a /boot EFI partition with 40M and arbitrary but fixed GUIDs for reproducibility
  
positive.code:         ''-append "$(cat ${config.system.build.toplevel}/kernel-params) init=${config.system.build.toplevel}/init regInfo=${regInfo}/registration ${consoles} $QEMU_KERNEL_PARAMS"''
        ])
        (mkIf cfg.useEFIBoot [
          "-pflash $TMPDIR/bios.bin"
        ])
        (mkIf (cfg.bios != null) [
          "-bios ${cfg.bios}/bios.bin"
  
negative.code:         ${qemu}/bin/qemu-img create -f qcow2 -b ${bootDisk}/disk.img $TMPDIR/disk.img || exit 1
  
          ${if cfg.useEFIBoot then ''
            # VM needs writable EFI vars
            cp ${bootDisk}/EFI_VARS.fd $TMPDIR || exit 1
            chmod 0644 $TMPDIR/EFI_VARS.fd || exit 1
          '' else ''
          ''}
        '' else ''
  