From 27d3b1b1578dab5c31ba1c34abab926987a1a494 Mon Sep 17 00:00:00 2001 From: Lin Jian Date: Wed, 1 Jan 2025 12:26:06 +0800 Subject: [PATCH] nixos/kmonad: create determinate symlinks (cherry picked from commit 9695e75dde3197dd10e3a4d9883e2daaeb6ee2f7) The 25.05 release note is manually removed. --- nixos/modules/services/hardware/kmonad.nix | 11 +++++++++++ nixos/tests/kmonad.nix | 2 ++ 2 files changed, 13 insertions(+) diff --git a/nixos/modules/services/hardware/kmonad.nix b/nixos/modules/services/hardware/kmonad.nix index 687224fae2e92..363a8e7028744 100644 --- a/nixos/modules/services/hardware/kmonad.nix +++ b/nixos/modules/services/hardware/kmonad.nix @@ -195,6 +195,17 @@ in config = lib.mkIf cfg.enable { hardware.uinput.enable = true; + services.udev.extraRules = + let + mkRule = name: '' + ACTION=="add", KERNEL=="event*", SUBSYSTEM=="input", ATTRS{name}=="${name}", ATTRS{id/product}=="5679", ATTRS{id/vendor}=="1235", SYMLINK+="input/by-id/${name}" + ''; + in + lib.foldlAttrs ( + rules: _: keyboard: + rules + "\n" + mkRule (mkName keyboard.name) + ) "" cfg.keyboards; + systemd = { paths = lib.mapAttrs' (_: mkPath) cfg.keyboards; services = lib.mapAttrs' (_: mkService) cfg.keyboards; diff --git a/nixos/tests/kmonad.nix b/nixos/tests/kmonad.nix index e0150cb99f183..9b0d47e578e42 100644 --- a/nixos/tests/kmonad.nix +++ b/nixos/tests/kmonad.nix @@ -43,5 +43,7 @@ with subtest("kmonad is running"): machine.succeed(f"systemctl status {service_name}") + with subtest("kmonad symlink is created"): + machine.wait_for_file(f"/dev/input/by-id/{service_name}", timeout=5) ''; }