summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorTimo Kaufmann <timokau@zoho.com>2022-03-07 18:51:08 +0100
committerGitHub <noreply@github.com>2022-03-07 18:51:08 +0100
commit94ea3a88999a92e9498584e728d5ac7b9e9f2882 (patch)
tree4fd6e0f735a6e2d66262eedf99b35a63daeeb81c /nixos
parent75ea3ea9b8c0beecc5db8ef8c429d9354573d776 (diff)
parent064362042091a21a75a682d7d9d0811e0033f73b (diff)
downloadnixpkgs-94ea3a88999a92e9498584e728d5ac7b9e9f2882.tar
nixpkgs-94ea3a88999a92e9498584e728d5ac7b9e9f2882.tar.gz
nixpkgs-94ea3a88999a92e9498584e728d5ac7b9e9f2882.tar.bz2
nixpkgs-94ea3a88999a92e9498584e728d5ac7b9e9f2882.tar.lz
nixpkgs-94ea3a88999a92e9498584e728d5ac7b9e9f2882.tar.xz
nixpkgs-94ea3a88999a92e9498584e728d5ac7b9e9f2882.tar.zst
nixpkgs-94ea3a88999a92e9498584e728d5ac7b9e9f2882.zip
Merge pull request #160777 from LunNova/improve-input-remapper-module
nixos/input-remapper: Fix missing [], add more options, add test
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/misc/input-remapper.nix27
-rw-r--r--nixos/tests/all-tests.nix1
-rw-r--r--nixos/tests/input-remapper.nix52
3 files changed, 67 insertions, 13 deletions
diff --git a/nixos/modules/services/misc/input-remapper.nix b/nixos/modules/services/misc/input-remapper.nix
index c2da0d616a3..f5fb2bf5308 100644
--- a/nixos/modules/services/misc/input-remapper.nix
+++ b/nixos/modules/services/misc/input-remapper.nix
@@ -7,23 +7,24 @@ let cfg = config.services.input-remapper; in
   options = {
     services.input-remapper = {
       enable = mkEnableOption "input-remapper, an easy to use tool to change the mapping of your input device buttons.";
-      package = mkOption {
-        type = types.package;
-        default = pkgs.input-remapper;
-        defaultText = literalExpression "pkgs.input-remapper";
-        description = ''
-          The input-remapper package to use.
-        '';
+      package = options.mkPackageOption pkgs "input-remapper" { };
+      enableUdevRules = mkEnableOption "udev rules added by input-remapper to handle hotplugged devices. Currently disabled by default due to https://github.com/sezanzeb/input-remapper/issues/140";
+      serviceWantedBy = mkOption {
+        default = [ "graphical.target" ];
+        example = [ "multi-user.target" ];
+        type = types.listOf types.str;
+        description = "Specifies the WantedBy setting for the input-remapper service.";
       };
     };
   };
 
   config = mkIf cfg.enable {
-    # FIXME: udev rule hangs sometimes when lots of devices connected, so let's not use it
-    # config.services.udev.packages = mapper-pkg;
-    services.dbus.packages = cfg.package;
-    systemd.packages = cfg.package;
-    environment.systemPackages = cfg.package;
-    systemd.services.input-remapper.wantedBy = [ "graphical.target" ];
+    services.udev.packages = mkIf cfg.enableUdevRules [ cfg.package ];
+    services.dbus.packages = [ cfg.package ];
+    systemd.packages = [ cfg.package ];
+    environment.systemPackages = [ cfg.package ];
+    systemd.services.input-remapper.wantedBy = cfg.serviceWantedBy;
   };
+
+  meta.maintainers = with lib.maintainers; [ LunNova ];
 }
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index 342e8f461b5..15b54cd9fe1 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -224,6 +224,7 @@ in
   initrd-network-ssh = handleTest ./initrd-network-ssh {};
   initrdNetwork = handleTest ./initrd-network.nix {};
   initrd-secrets = handleTest ./initrd-secrets.nix {};
+  input-remapper = handleTest ./input-remapper.nix {};
   inspircd = handleTest ./inspircd.nix {};
   installer = handleTest ./installer.nix {};
   invoiceplane = handleTest ./invoiceplane.nix {};
diff --git a/nixos/tests/input-remapper.nix b/nixos/tests/input-remapper.nix
new file mode 100644
index 00000000000..f692564caa5
--- /dev/null
+++ b/nixos/tests/input-remapper.nix
@@ -0,0 +1,52 @@
+import ./make-test-python.nix ({ pkgs, ... }:
+
+  {
+    name = "input-remapper";
+    meta = {
+      maintainers = with pkgs.lib.maintainers; [ LunNova ];
+    };
+
+    machine = { config, ... }:
+      let user = config.users.users.sybil; in
+      {
+        imports = [
+          ./common/user-account.nix
+          ./common/x11.nix
+        ];
+
+        services.xserver.enable = true;
+        services.input-remapper.enable = true;
+        users.users.sybil = { isNormalUser = true; group = "wheel"; };
+        test-support.displayManager.auto.user = user.name;
+        # workaround for pkexec not working in the test environment
+        # Error creating textual authentication agent:
+        #   Error opening current controlling terminal for the process (`/dev/tty'):
+        #   No such device or address
+        # passwordless pkexec with polkit module also doesn't work
+        # to allow the program to run, we replace pkexec with sudo
+        # and turn on passwordless sudo
+        # this is not correct in general but good enough for this test
+        security.sudo = { enable = true; wheelNeedsPassword = false; };
+        security.wrappers.pkexec = pkgs.lib.mkForce
+          {
+            setuid = true;
+            owner = "root";
+            group = "root";
+            source = "${pkgs.sudo}/bin/sudo";
+          };
+      };
+
+    enableOCR = true;
+
+    testScript = { nodes, ... }: ''
+      start_all()
+      machine.wait_for_x()
+
+      machine.succeed("systemctl status input-remapper.service")
+      machine.execute("su - sybil -c input-remapper-gtk >&2 &")
+
+      machine.wait_for_text("Input Remapper")
+      machine.wait_for_text("Preset")
+      machine.wait_for_text("Change Key")
+    '';
+  })