I wish to have an unpatched version of the QEMU (which allows me to use VirtIO for better performance) and a patched version of QEMU to co-exist simultaneously in my environment. The attempt went pretty fr and successful in terms of making multiple versions of QEMU exist, but I cannot make libvirt recognize them.
let
# special anti-detection emulator
qemu-anti-detection =
(pkgs.qemu.override{
hostCpuOnly = true;
}).overrideAttrs (finalAttrs:
previousAttrs: {
# ref: https://github.com/zhaodice/qemu-anti-detection
patches = (previousAttrs.patches or [ ]) ++ [
(pkgs.fetchpatch {
url =
"https://raw.githubusercontent.com/zhaodice/qemu-anti-detection/main/qemu-8.1.0.patch";
sha256 = "sha256-N+3YRvOwIu+k1d0IYxwV6zWmfJT9jle38ywOWTbgX8Y=";
})
];
postFixup = (previousAttrs.postFixup or "") + "\n" + ''
for i in $(find $out/bin -type f -executable); do
mv $i "$i-anti-detection"
done
'';
version = "8.1.2";
pname = "qemu-anti-detection";
});
in {
# ref: https://github.com/NixOS/nixpkgs/issues/115996
virtualisation.libvirtd = {
allowedBridges = [ "nm-bridge" "virbr0" ];
enable = true;
qemu = {
runAsRoot = false;
package = pkgs.qemu_kvm;
};
package = pkgs.yubo.libvirt.override {
extraEmulators = [
qemu-anti-detection
pkgs.qemu_kvm
];
};
};
programs.virt-manager.enable = true;
environment.systemPackages =
[ qemu-anti-detection ];
}
The result of the above code snippet is that qemu-system-x86_64-anti-detection
is added to the PATH
. However, it seems that I need to add it to /run/libvirt/nix-emulators
somehow so that libvirt
can also use this as an emulator. Currently, every time I attempt to set the emulator directly to libvirt
, the following error occurs
error: internal error: Failed to start QEMU binary /run/current-system/sw/bin/qemu-system-x86_64-anti-detection for probing:
I have tried to add custom packages to libvirt
package’s binPath
, but to no avail, that doesn’t work, nor would Nix allow me to ln
those executable directly to the /run
directory while building qemu
.