at 23.11-pre 2.3 kB view raw
1{ config, lib, pkgs, ... }: 2 3let 4 cfg = config.services.persistent-evdev; 5 settingsFormat = pkgs.formats.json {}; 6 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; 10 }; 11in 12{ 13 options.services.persistent-evdev = { 14 enable = lib.mkEnableOption (lib.mdDoc "virtual input devices that persist even if the backing device is hotplugged"); 15 16 devices = lib.mkOption { 17 default = {}; 18 type = with lib.types; attrsOf str; 19 description = lib.mdDoc '' 20 A set of virtual proxy device labels with backing physical device ids. 21 22 Physical devices should already exist in {file}`/dev/input/by-id/`. 23 Proxy devices will be automatically given a `uinput-` prefix. 24 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)). 29 ''; 30 example = lib.literalExpression '' 31 { 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"; 37 } 38 ''; 39 }; 40 }; 41 42 config = lib.mkIf cfg.enable { 43 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" ]; 48 49 serviceConfig = { 50 Restart = "on-failure"; 51 ExecStart = "${pkgs.persistent-evdev}/bin/persistent-evdev.py ${configFile}"; 52 CacheDirectory = "persistent-evdev"; 53 }; 54 }; 55 56 services.udev.packages = [ pkgs.persistent-evdev ]; 57 }; 58 59 meta.maintainers = with lib.maintainers; [ lodi ]; 60}