1 { config, lib, pkgs, ... }:
4 cfg = config.services.persistent-evdev;
5 settingsFormat = pkgs.formats.json {};
7 configFile = settingsFormat.generate "persistent-evdev-config" {
8 cache = "/var/cache/persistent-evdev";
9 devices = lib.mapAttrs (virt: phys: "/dev/input/by-id/${phys}") cfg.devices;
13 options.services.persistent-evdev = {
14 enable = lib.mkEnableOption "virtual input devices that persist even if the backing device is hotplugged";
16 devices = lib.mkOption {
18 type = with lib.types; attrsOf str;
20 A set of virtual proxy device labels with backing physical device ids.
22 Physical devices should already exist in {file}`/dev/input/by-id/`.
23 Proxy devices will be automatically given a `uinput-` prefix.
25 See the [project page](https://github.com/aiberia/persistent-evdev#example-usage-with-libvirt)
26 for example configuration of virtual devices with libvirt
27 and remember to add `uinput-*` devices to the qemu
28 `cgroup_device_acl` list (see [](#opt-virtualisation.libvirtd.qemu.verbatimConfig)).
30 example = lib.literalExpression ''
32 persist-mouse0 = "usb-Logitech_G403_Prodigy_Gaming_Mouse_078738533531-event-if01";
33 persist-mouse1 = "usb-Logitech_G403_Prodigy_Gaming_Mouse_078738533531-event-mouse";
34 persist-mouse2 = "usb-Logitech_G403_Prodigy_Gaming_Mouse_078738533531-if01-event-kbd";
35 persist-keyboard0 = "usb-Microsoft_NaturalĀ®_Ergonomic_Keyboard_4000-event-kbd";
36 persist-keyboard1 = "usb-Microsoft_NaturalĀ®_Ergonomic_Keyboard_4000-if01-event-kbd";
42 config = lib.mkIf cfg.enable {
44 systemd.services.persistent-evdev = {
45 documentation = [ "https://github.com/aiberia/persistent-evdev/blob/master/README.md" ];
46 description = "Persistent evdev proxy";
47 wantedBy = [ "multi-user.target" ];
50 Restart = "on-failure";
51 ExecStart = "${pkgs.persistent-evdev}/bin/persistent-evdev.py ${configFile}";
52 CacheDirectory = "persistent-evdev";
56 services.udev.packages = [ pkgs.persistent-evdev ];
59 meta.maintainers = with lib.maintainers; [ lodi ];