Pass an environment variable to qemu

,

Good evening everybody,

I’m using incus 1:6.7-ubuntu24.04-202411151754 from zabbly on debian trixie with debian’s qemu (1:9.1.1+ds-5) as it supports pipewire and I’m struggling to pass a environment variable to qemu.

incus config set myvm environment.PIPEWIRE_RUNTIME_DIR='/mydir'
doesn’t seem to work, as starting the vm fails with

qemu-system-x86_64: Failed to initialize PW context

What I’m trying to do is to output the sound of myvm directly to pipewire.

When I’m bind-mounting my user’s pipewire-socket
mount /run/user/1000/pipewire-0 -o bind,rw /mydir/pipewire-0
I can confirm the incus user is able to play sound through pipewire with:
sudo -u incus PIPEWIRE_RUNTIME_DIR=/mydir pw-cat -p /usr/share/sounds/alsa/Side_Left.wav

I can also confirm that sound comes out of myvm by setting
incus config set myvm raw.qemu='-audiodev spice,id=audio0 -device intel-hda -device hda-output,audiodev=audio0' and running virt-viewer or by using pulseaudio.

Both pulseaudio and spice have latency and/or crackling noise, which I’m trying to avoid by using pipewire directly:
incus config set myvm raw.qemu='-audiodev pipewire,id=audio0 -device intel-hda -device hda-output,audiodev=audio0'

Unfortunately, qemu’s seems to have no way to specify pipewire’s runtime directory on the command line and instead relies on the PIPEWIRE_RUNTIME_DIR environment variable, so I need to get that through to qemu.

Thanks in advance for any help!
Christoph

P.S. For the curious trying to reproduce: For the sake of simplicity I left out one step. You need to get apparmor out of the way with

incus config set myvm raw.apparmor='/etc/pipewire/* r, /usr/share/pipewire/* r, /mydir/pipewire-0 rw,

Welcome!

When you launch a container or a VM, Incus has little influence as to what is running in there. Because Incus has to be as generic as possible.

Having said that, incus config set myvm environment. will set a configuration for the shell environment when you later get a shell into the instance. In your case though, you want to set a system-level environment variable.

I believe for a system-level environment you would need to edit /etc/environment or something similar.

Thanks a lot, simos, for your explanation and solution!

That was the missing link.
I ended up putting my environment variable into /etc/default/incus to avoid messing up audio setup for other users of the host.

Thanks again!