-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/qemu-vm: add opengl hardware acceleration option #279009
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the mkMerge
necessary for the merging or could you get away with a simple lib.optional
and ++
? Other than that, it looks mostly good to me. Is there a way to easily verify it's doing what it's supposed to do on a x86 machine? Just running some FPS stuff?
6120452
to
5cc86a1
Compare
Oh I would normally would use I was just starting to replace all uses of
I was verifying the change through my nixos config with {
inputs.nixpkgs.url = "github:kira-bruneau/nixpkgs/qemu-vm-opengl";
outputs = { self, nixpkgs }: {
packages.x86_64-linux.default = (nixpkgs.lib.nixosSystem {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
modules = [
({ pkgs, ... }: {
system.stateVersion = "23.11";
programs.sway.enable = true;
services.getty.autologinUser = "root";
programs.bash.loginShellInit = ''
if [ "$(tty)" = "/dev/tty1" ]; then
sway --config ${pkgs.writeText "glxgears" ''
exec ${pkgs.mangohud}/bin/mangohud ${pkgs.mesa-demos}/bin/glxgears -fullscreen
''}
fi
'';
})
];
}).config.system.build.vm;
};
} I didn't add a new test for this because hardware acceleration can't be used within the context of a test, but I updated a bunch of existing tests to enable it when running interactively. For example: nix run github:kira-bruneau/nixpkgs/qemu-vm-opengl#nixosTests.gnome.driverInteractive
>>> start_all() |
a14fda2
to
e631bf3
Compare
Is it safe to enable VirGL by default? What if the guest has Also, is it really that important to enable it in all these tests? I'd rather keep the changes limited to qemu-vm.nix. |
I tested with
Given that the xserver module enables Footnotes
|
ping |
Oops sorry!! I forgot to get back to this. I was trying to figure out a general way to enable this by default without breaking cli-only & spice setups, but I couldn't really come up with a good solution - so I'll keep the option, but leave it disabled by default.
It's not essential, but I think it would be nice to have, since those VMs are a lot more pleasant to debug with hardware acceleration. The changes I made only apply to the interactive driver, which wouldn't have any impact on how the tests runs in hydra. |
e631bf3
to
b78e148
Compare
b78e148
to
3c75524
Compare
This makes it possible to run most Wayland compositors inside a VM and enables hardware acceleration for X11 desktop environments when `hardware.opengl.enable = true` (without resorting to GPU passthrough or software rendering). Compositors like gamescope which rely on Vulkan still aren't supported out of the box. Though, it looks like we could eventually support this if we enable & use rutabaga when building qemu. NOTE: I haven't tested this on aarch64-linux & darwin, but I assume it should work based on the usage instructions I found at https://github.com/knazarov/homebrew-qemu-virgl#usage---m1-macs.
98e4f22
to
0c262a0
Compare
0c262a0
to
2373dc1
Compare
I like this idea, and it'd be great to have more performant graphics on NixOS VMs.
If/when this happens, what option would we use? Perhaps instead of |
When I checkout this PR, and run a test in interactive mode, qemu fails to start:
I'm running this on Debian Testing, on Wayland, with an amdgpu card/driver.
I'll test this later on my NixOS machine. Maybe the nix provided Qemu is unable to find the EGL implementation on my Debian Testing machine. My graphics stack-fu is weak. |
Works fine on my NixOS machine.
I'm not sure whether running nixosTests from non-NixOS is a supported usecase. It would be a shame to hamstring ourselves (see the workarounds that this PR removes) to a lowest-common denominator of QEMU support. Is there a way to get working OpenGL passthrough from QEMU, when run via nix-build on a non-NixOS distro? |
OpenGL probably is not working on non-NixOS for the usual reasons. Have you tried NixGL? |
TIL the usual reasons #9415 . I'll try NixGL sometime, thanks. With respect to this PR, I think it's fine if non-NixOS users are unable to interactively run NixOS tests for the few tests that rely on OpenGL. |
I tested whether NixGL allowed this PR's tests to be run from Debian Testing. It worked! |
It would be better if the test simply turned OpenGL off instead of hard failing, though. |
Description of changes
VMs built with
hardware.opengl.enable = true
will now use opengl hardware acceleration backed by VirGL.This makes it possible to run most Wayland compositors in a VM, and enables hardware acceleration for X11 desktop environments.
Hardware acceleration can also be enabled when running a test VM interactively with:
Compositors like gamescope which rely on Vulkan still aren't supported out of the box. Although, it looks like we could eventually support this if we enable & use rutabaga when building qemu.
NOTE: I haven't tested this on aarch64-linux & darwin, but I assume it should work based on the similar usage instructions I found at https://github.com/knazarov/homebrew-qemu-virgl#usage---m1-macs.
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.