~sirn/udev-forwarder

A simple daemon that forward matching USB devices to libvirt VM

clone

read-only
https://git.sr.ht/~sirn/udev-forwarder
read/write
git@git.sr.ht:~sirn/udev-forwarder

You can also use your local clone with git send-email.

#udev-forwarder

A simple daemon that listens for udev events and forward matching devices to libvirt VM.

#Usage

$ udev-forwarder /path/to/config.toml

#Basic Configuration

uri = "qemu:///system"

[[domain]]
name = "win11"

[[domain.match]]
devpath = "/devices/pci0000:00/0000:00:14.0/usb1/1-9"

[[domain.match]]
devpath = "/devices/pci0000:00/0000:00:14.0/usb1/1-11"

[[domain]]
name = "ubuntu"

[[domain.match]]
devpath = "/devices/pci0000:00/0000:00:14.0/usb1/1-14"

There can be multiple domains and multiple matches per domain. Currently only devpath is supported.

#Why?

I've been using ipatix/libvirt-usb-hotplug with great success for the past few years. Recently, I've moved my VMs to an immutable system. This unfortunately makes setting up an udev hook a bit more complicated than I hoped to. For example, NixOS disallows referencing hooks outside of the nix store tree (which is needed, since libvirt-usb-hotplug configuration is done inside the script itself; either that or I need to fork the script).

Instead of doing that, I opted for a small binary that can be set up as a daemon (which doesn't require root). The script uses libudev to listen for udev events, and forward the matching USB devices using libvirt binding. This allows the binary to be run as non-root, as long as it can access udev events and can access libvirt system socket (i.e. libvirtd group).

#License

BSD-3-Clause