about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSandro <sandro.jaeckel@gmail.com>2022-06-07 23:46:13 +0200
committerGitHub <noreply@github.com>2022-06-07 23:46:13 +0200
commitbe96e2412471eb184491d2e0485357949cf65378 (patch)
tree925b39c53664b245f9664cd3ab42fae3a5b5eb15
parentcf68deab17fde49169ff8d8217d936f7d235385d (diff)
parent3f1ec25f902bf6cb93db3600d3f6cd69234e4b9d (diff)
Merge pull request #163226 from lodi/persistent-evdev
persistent-evdev: init at unstable-2022-01-14
-rw-r--r--nixos/doc/manual/from_md/release-notes/rl-2211.section.xml9
-rw-r--r--nixos/doc/manual/release-notes/rl-2211.section.md1
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/misc/persistent-evdev.nix60
-rw-r--r--pkgs/servers/persistent-evdev/default.nix42
-rw-r--r--pkgs/top-level/all-packages.nix2
6 files changed, 115 insertions, 0 deletions
diff --git a/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml
index 83f2d10225140..5c29f98b28dfb 100644
--- a/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml
+++ b/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml
@@ -62,6 +62,15 @@
           <link xlink:href="options.html#opt-services.infnoise.enable">services.infnoise</link>.
         </para>
       </listitem>
+      <listitem>
+        <para>
+          <link xlink:href="https://github.com/aiberia/persistent-evdev">persistent-evdev</link>,
+          a daemon to add virtual proxy devices that mirror a physical
+          input device but persist even if the underlying hardware is
+          hot-plugged. Available as
+          <link linkend="opt-services.persistent-evdev.enable">services.persistent-evdev</link>.
+        </para>
+      </listitem>
     </itemizedlist>
   </section>
   <section xml:id="sec-release-22.11-incompatibilities">
diff --git a/nixos/doc/manual/release-notes/rl-2211.section.md b/nixos/doc/manual/release-notes/rl-2211.section.md
index 85adae269c318..624bde2c83d77 100644
--- a/nixos/doc/manual/release-notes/rl-2211.section.md
+++ b/nixos/doc/manual/release-notes/rl-2211.section.md
@@ -29,6 +29,7 @@ In addition to numerous new and upgraded packages, this release has the followin
 
 - [infnoise](https://github.com/leetronics/infnoise), a hardware True Random Number Generator dongle.
   Available as [services.infnoise](options.html#opt-services.infnoise.enable).
+- [persistent-evdev](https://github.com/aiberia/persistent-evdev), a daemon to add virtual proxy devices that mirror a physical input device but persist even if the underlying hardware is hot-plugged. Available as [services.persistent-evdev](#opt-services.persistent-evdev.enable).
 
 <!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
 
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 7b1054262f590..d67602a267612 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -606,6 +606,7 @@
   ./services/misc/packagekit.nix
   ./services/misc/paperless.nix
   ./services/misc/parsoid.nix
+  ./services/misc/persistent-evdev.nix
   ./services/misc/plex.nix
   ./services/misc/plikd.nix
   ./services/misc/podgrab.nix
diff --git a/nixos/modules/services/misc/persistent-evdev.nix b/nixos/modules/services/misc/persistent-evdev.nix
new file mode 100644
index 0000000000000..401d20010b12a
--- /dev/null
+++ b/nixos/modules/services/misc/persistent-evdev.nix
@@ -0,0 +1,60 @@
+{ config, lib, pkgs, ... }:
+
+let
+  cfg = config.services.persistent-evdev;
+  settingsFormat = pkgs.formats.json {};
+
+  configFile = settingsFormat.generate "persistent-evdev-config" {
+    cache = "/var/cache/persistent-evdev";
+    devices = lib.mapAttrs (virt: phys: "/dev/input/by-id/${phys}") cfg.devices;
+  };
+in
+{
+  options.services.persistent-evdev = {
+    enable = lib.mkEnableOption "virtual input devices that persist even if the backing device is hotplugged";
+
+    devices = lib.mkOption {
+      default = {};
+      type = with lib.types; attrsOf str;
+      description = ''
+        A set of virtual proxy device labels with backing physical device ids.
+
+        Physical devices should already exist in <filename class="devicefile">/dev/input/by-id/</filename>.
+        Proxy devices will be automatically given a <literal>uinput-</literal> prefix.
+
+        See the <link xlink:href="https://github.com/aiberia/persistent-evdev#example-usage-with-libvirt">
+        project page</link> for example configuration of virtual devices with libvirt
+        and remember to add <literal>uinput-*</literal> devices to the qemu
+        <literal>cgroup_device_acl</literal> list (see <xref linkend="opt-virtualisation.libvirtd.qemu.verbatimConfig"/>).
+      '';
+      example = lib.literalExpression ''
+        {
+          persist-mouse0 = "usb-Logitech_G403_Prodigy_Gaming_Mouse_078738533531-event-if01";
+          persist-mouse1 = "usb-Logitech_G403_Prodigy_Gaming_Mouse_078738533531-event-mouse";
+          persist-mouse2 = "usb-Logitech_G403_Prodigy_Gaming_Mouse_078738533531-if01-event-kbd";
+          persist-keyboard0 = "usb-Microsoft_NaturalĀ®_Ergonomic_Keyboard_4000-event-kbd";
+          persist-keyboard1 = "usb-Microsoft_NaturalĀ®_Ergonomic_Keyboard_4000-if01-event-kbd";
+        }
+      '';
+    };
+  };
+
+  config = lib.mkIf cfg.enable {
+
+    systemd.services.persistent-evdev = {
+      documentation = [ "https://github.com/aiberia/persistent-evdev/blob/master/README.md" ];
+      description = "Persistent evdev proxy";
+      wantedBy = [ "multi-user.target" ];
+
+      serviceConfig = {
+        Restart = "on-failure";
+        ExecStart = "${pkgs.persistent-evdev}/bin/persistent-evdev.py ${configFile}";
+        CacheDirectory = "persistent-evdev";
+      };
+    };
+
+    services.udev.packages = [ pkgs.persistent-evdev ];
+  };
+
+  meta.maintainers = with lib.maintainers; [ lodi ];
+}
diff --git a/pkgs/servers/persistent-evdev/default.nix b/pkgs/servers/persistent-evdev/default.nix
new file mode 100644
index 0000000000000..c666e9c8d799e
--- /dev/null
+++ b/pkgs/servers/persistent-evdev/default.nix
@@ -0,0 +1,42 @@
+{ lib, buildPythonPackage, fetchFromGitHub, python3Packages }:
+
+buildPythonPackage rec {
+  pname = "persistent-evdev";
+  version = "unstable-2022-05-07";
+
+  src = fetchFromGitHub {
+    owner = "aiberia";
+    repo = pname;
+    rev = "52bf246464e09ef4e6f2e1877feccc7b9feba164";
+    sha256 = "d0i6DL/qgDELet4ew2lyVqzd9TApivRxL3zA3dcsQXY=";
+  };
+
+  propagatedBuildInputs = with python3Packages; [
+    evdev pyudev
+  ];
+
+  postPatch = ''
+    patchShebangs bin/persistent-evdev.py
+  '';
+
+  dontBuild = true;
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp bin/persistent-evdev.py $out/bin
+
+    mkdir -p $out/etc/udev/rules.d
+    cp udev/60-persistent-input-uinput.rules $out/etc/udev/rules.d
+  '';
+
+  # has no tests
+  doCheck = false;
+
+  meta = with lib; {
+    homepage = "https://github.com/aiberia/persistent-evdev";
+    description = "Persistent virtual input devices for qemu/libvirt/evdev hotplug support";
+    license = licenses.mit;
+    maintainers = [ maintainers.lodi ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index bd878b1669ca6..4c9ef168932fe 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -4757,6 +4757,8 @@ with pkgs;
 
   evdevremapkeys = callPackage ../tools/inputmethods/evdevremapkeys { };
 
+  persistent-evdev = python3Packages.callPackage ../servers/persistent-evdev { };
+
   evscript = callPackage ../tools/inputmethods/evscript { };
 
   gebaar-libinput = callPackage ../tools/inputmethods/gebaar-libinput { stdenv = gcc10StdenvCompat; };