# Opengl can not be used with libvirt

**URL:** https://discourse.nixos.org/t/opengl-can-not-be-used-with-libvirt/43688
**Category:** Help
**Created:** [April 19, 2024, 7:07am UTC](https://discourse.nixos.org/t/opengl-can-not-be-used-with-libvirt/43688 "2024-04-19T07:07:15Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![SongguokunSgg](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/s/a9a28c/32.png) [@SongguokunSgg](https://discourse.nixos.org/u/SongguokunSgg)
#### Post date: [April 19, 2024, 7:07am UTC](https://discourse.nixos.org/t/opengl-can-not-be-used-with-libvirt/43688/1 "2024-04-19T07:07:15Z")

</div>

![image](https://discourse.nixos.org/uploads/default/original/3X/1/b/1b199ecbb9dc3e4cf1434432f038560d2d345394.png)  
A virtual system “win10LTSC” was created, and I can use is normally. All virtio driver were installed, but when I change the video module to virtio, and turn on the 3D acceleration, the virtual system can not work.

```auto
启动域时出错: internal error: QEMU unexpectedly closed the monitor (vm='win10LTSC'): 2024-04-19T07:08:43.068983Z qemu-system-x86_64: -device {"driver":"virtio-vga-gl","id":"video0","max_outputs":1,"bus":"pcie.0","addr":"0x1"}: opengl is not available

Traceback (most recent call last):
  File "/nix/store/kg0k9xb64dziq1zbbjiyxd81nbqs9j7p-virt-manager-4.1.0/share/virt-manager/virtManager/asyncjob.py", line 72, in cb_wrapper
    callback(asyncjob, *args, **kwargs)
  File "/nix/store/kg0k9xb64dziq1zbbjiyxd81nbqs9j7p-virt-manager-4.1.0/share/virt-manager/virtManager/asyncjob.py", line 108, in tmpcb
    callback(*args, **kwargs)
  File "/nix/store/kg0k9xb64dziq1zbbjiyxd81nbqs9j7p-virt-manager-4.1.0/share/virt-manager/virtManager/object/libvirtobject.py", line 57, in newfn
    ret = fn(self, *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/kg0k9xb64dziq1zbbjiyxd81nbqs9j7p-virt-manager-4.1.0/share/virt-manager/virtManager/object/domain.py", line 1402, in startup
    self._backend.create()
  File "/nix/store/lwln0g2amirg6xjclcfvkq4kbbip9kz1-python3.11-libvirt-9.9.0/lib/python3.11/site-packages/libvirt.py", line 1373, in create
    raise libvirtError('virDomainCreate() failed')
libvirt.libvirtError: internal error: QEMU unexpectedly closed the monitor (vm='win10LTSC'): 2024-04-19T07:08:43.068983Z qemu-system-x86_64: -device {"driver":"virtio-vga-gl","id":"video0","max_outputs":1,"bus":"pcie.0","addr":"0x1"}: opengl is not available

```

But I had install it

```auto
...
        hardware = {
                bluetooth = {
                        enable = true;
                        powerOnBoot = true;
                };
                opengl.enable = true;
        };
...
        virtualisation = { 
                docker = {
                        enable = true;
                        storageDriver = "btrfs";
                };
                libvirtd.enable = true;
# waydroid.enable = true;
        };

```

and I can find opengl module in

```auto
/run/opengl-driver » tree sukipai@SUKIPAI
.
├── lib -> /nix/store/zwsvcpspvdykjz1i1rpjz7f3msvhpdca-mesa-23.1.9-drivers/lib
└── share -> /nix/store/zwsvcpspvdykjz1i1rpjz7f3msvhpdca-mesa-23.1.9-drivers/share

3 directories, 0 files

```

I want to know why?And I can only use the QXL model now. 😭

---

<div class="post-metadata">

### Author: ![AkechiShiro](https://discourse.nixos.org/user_avatar/discourse.nixos.org/akechishiro/32/4926_2.png) [@AkechiShiro](https://discourse.nixos.org/u/AkechiShiro)
#### Post date: [April 30, 2024, 11:59am UTC](https://discourse.nixos.org/t/opengl-can-not-be-used-with-libvirt/43688/2 "2024-04-30T11:59:20Z")

</div>

Running into the same issue at the moment, @SongguokunSgg have you opened an issue on GitHub for this ?  
I didn’t find any about this but I’ve seen Nvidia GPUs have bugs with QEMU/libvirt 3D acceleration upstream see : [libvirt: openGL does not work with Nvidia GPUs · Issue #164436 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/issues/164436)

---

<div class="post-metadata">

### Author: ![SongguokunSgg](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/s/a9a28c/32.png) [@SongguokunSgg](https://discourse.nixos.org/u/SongguokunSgg)
#### Post date: [April 30, 2024, 3:20pm UTC](https://discourse.nixos.org/t/opengl-can-not-be-used-with-libvirt/43688/3 "2024-04-30T15:20:23Z")

</div>

I had solved this problem. You should turn on the OpenGL in spice label, and turn the 3d accelerat in virtue.

---

<div class="post-metadata">

### Author: ![AkechiShiro](https://discourse.nixos.org/user_avatar/discourse.nixos.org/akechishiro/32/4926_2.png) [@AkechiShiro](https://discourse.nixos.org/u/AkechiShiro)
#### Post date: [April 30, 2024, 4:57pm UTC](https://discourse.nixos.org/t/opengl-can-not-be-used-with-libvirt/43688/4 "2024-04-30T16:57:36Z")

</div>

In space label (channel ?) I don’t see OpenGL :  
 ![image](https://discourse.nixos.org/uploads/default/original/3X/e/6/e68d799066a12638f4c2314a9056fb27cd8c2e0c.png)

---

<div class="post-metadata">

### Author: ![AkechiShiro](https://discourse.nixos.org/user_avatar/discourse.nixos.org/akechishiro/32/4926_2.png) [@AkechiShiro](https://discourse.nixos.org/u/AkechiShiro)
#### Post date: [April 30, 2024, 5:13pm UTC](https://discourse.nixos.org/t/opengl-can-not-be-used-with-libvirt/43688/5 "2024-04-30T17:13:18Z")

</div>

I found this I think it’s probably this checkbox :  
 ![image](https://discourse.nixos.org/uploads/default/original/3X/d/8/d8791e9480f4a78052dc038644f5c268fe6d31b2.png)  
I also had to change Listen type from `address` to `none`

---

<div class="post-metadata">

### Author: ![emmanuelrosa](https://discourse.nixos.org/user_avatar/discourse.nixos.org/emmanuelrosa/32/1924_2.png) [@emmanuelrosa](https://discourse.nixos.org/u/emmanuelrosa)
#### Post date: [April 30, 2024, 6:19pm UTC](https://discourse.nixos.org/t/opengl-can-not-be-used-with-libvirt/43688/6 "2024-04-30T18:19:03Z")

</div>

Yes, [AkechiShiro](https://discourse.nixos.org/u/AkechiShiro) is correct.

1. Video: set model to Virtio, and 3D acceleration needs to be enabled.
2. Spice server: set “Listen type” to None, enable OpenGL, and then select a non-NVIDIA GPU.
