A simple daemon that forward matching USB devices to libvirt VM



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


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


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

#Basic Configuration

uri = "qemu:///system"

name = "win11"

devpath = "/devices/pci0000:00/0000:00:14.0/usb1/1-9"

devpath = "/devices/pci0000:00/0000:00:14.0/usb1/1-11"

name = "ubuntu"

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.


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).