This guide assumes you followed u/neowutran's guide on creating a sys-audio qube It is also highly recommended to have a disposable sys-usb if you are using external usb dongles or just in general.
Purpose:
On some devices using the qvm-device usb attach --persistent sys-audio sys-usb:(usb-id)
doesn't stay persistent this guide aims to be the solution.
Setting up DOM0:
First run qubes-dom0-update vim
First thing you want to do is figure out your Bluetooth device dongle identifier
to do this in dom0 runqvm-run --pass-io sys-usb lsusb
. For me my Bluetooth usb device is
Bus (00#) Device (00#): ID 8087:07dc Intel Corp. Bluetooth wireless interface
Now remember the id which for me would be 8087:07dc
Next run sudo vim /etc/qubes-rpc/audio.vm.bluetooth
And paste or type in the following script:
#!/usr/bin/bash
#Script to check if qube is fully booted before breaking off to attach bluetooth device
#This is necessary for boot
while [ $( /usr/bin/qvm-run --pass-io --no-colour-stderr sys-usb "/usr/bin/systemctl is-system-running") != "running" ]
do
sleep 1
done
ID="8087:07dc" #add your Bluetooth-USB id here
qvm-device usb attach sys-audio "$(qvm-device usb ls | grep $ID | awk '{print $1}')" && qvm-run sys-audio "blueman-applet & disown"
#We enable Blueman applet with qvm-run because the Blueman icon will refuse to run if no Bluetooth adapter is detected during boot
#We connect the Bluetooth adapter after boot
Dont Forget to run chmod +x /etc/qubes-rpc/audio.vm.bluetooth
and edit the ID value
In /etc/qubes-rpc/policy
run sudo vim /etc/qubes-rpc/policy/audio.vm.bluetooth
Paste in or type the following:
sys-audio dom0 allow
sys-usb dom0 allow #Required for external dongles but not recommended for built in
Setup in dom0 is complete
For External USB Bluetooth Dongles only If you have a built in USB dongle skip this section
Warning: The following section is experimental theory and was emulated with keyboard USB dongles,internal Bluetooth dongles and not external Bluetooth dongles, as the author doesn't possess one this may take some tinkering to make this work,Please check the comments for confirmation on this working,Make sure your device BT device drivers are installed in sys-audio's Non-Dvm Template(Most likely audio-template)
Open a terminal in sys-usb
And run sudo udevadm monitor --environment
in the terminal then insert(Or reinsert) your bluetooth usb device and terminate the program.
You should get output containing ACTION=ADD , SUBSYSTEM=usb, and some sortof identifier like ID_VENDOR,ID_SERIAL,etc,For this tutorial I will be using ID_SERIAL, this will be important later.
open a terminal in sys-usb's template in the templates tab (You can figure out your template by running qvm-prefs sys-usb | grep -i template
It doesn't matter if your template is disposable or not but disposables are recommended, if your sys-usb isn't disposable just do all the following steps directly in sys-usb.Also make sure to keep sys-usb's terminal open with the values of the identifiers in this case ID_SERIAL.
In sys-usb's dvm template (use sys-usb directly if your sys-usb is not a dvm)
add the following:
sudo vim /rw/config/bt-autoconnect.rules
ACTION=="add", SUBSYSTEM=="usb", ENV{ID_SERIAL}=="SERIALNUMBERHERE", RUN+="/usr/bin/qrexec-client-vm dom0 audio.vm.bluetooth"
#Executes code in /etc/qubes-rpc
make sure to replace SERIALNUMBERHERE With The Value ID_SERIAL from the udevadm monitor --environment
command that we used earlier
run sudo vim /rw/config/rc.local
and add the following
#!/usr/bin/bash
ln -s /rw/config/bt-autoconnect.rules /etc/udev/rules.d
udevadm control --reload
Write and save all these changes and shutdown sys-usb and sys-usb's dvm (Probably default-dvm if you didn't change it)
now if you did this right you should be able to boot up sys-usb and plug in your Bluetooth adapter and it should auto-connect to the sys-audio VM.
make sure in sys-audio Blueman is installed and the Bluetooth service is enabled also make sure you used the id's for the same USB device in dom0's /etc/qubes-rpc as you did sys-usb's bt-autoconnect.rules file.
For built in USB dongles:
Open the dvm sys-audio is based on (Should be audio-app)
open the terminal in audio-app and run sudo vim /rw/config/rc.local
and paste in the following
/usr/bin/qrexec-client-vm dom0 audio.vm.bluetooth &
shutdown the template and restart sys-audio
If you get a message saying device attach failed restart dom0