NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.44k stars 13.64k forks source link

Udev keyboard remapping: ExtraHwdb does not work anymore? #182966

Open tobiasBora opened 2 years ago

tobiasBora commented 2 years ago

Describe the bug

I tried to remap some keys in NixOs (Menu key to the key producing <> as US keyboards lack this key present on french keyboards). However, nothing works. I even tried to test the test-script proposed here proposed by @rnhmjoj :

import nixos/tests/make-test-python.nix ({...} :

{
  name = "swapping-keyboard-keys";

  machine = { pkgs, ... }:
    {
      documentation.enable = false;
      users.users.root.password = "";
      services.udev.extraHwdb =
        ''
          evdev:name:AT Translated Set 2 keyboard:*
           KEYBOARD_KEY_2c=x  # z -> x
           KEYBOARD_KEY_2d=z  # x -> z
        '';
    };

  testScript =
    ''
      machine.start()
      machine.wait_for_unit("getty.target")
      machine.sleep(2)
      machine.send_chars("root\n")
      machine.sleep(2)
      machine.send_key("ret")
      machine.sleep(2)
      machine.send_chars("echo zx > /test\n")
      machine.wait_for_file("/test")
      machine.succeed("grep -q xz /test")
    '';
})

but this test fails (it succeeds if we replace the last xz with zx, meaning that the change was not taken into account).

Steps To Reproduce

Steps to reproduce the behavior:*

  1. Create the above file and run nix-build on it.

Otherwise, I tried directly on my own system many combinaison like:

   service.udev.extraHwdb = ''
     keyboard:usb:v*p*
     KEYBOARD_KEY_70065=102nd
   '';
  # Or
  service.udev.extraHwdb = ''
     evdev:input:b0003v045Ep00DB*
     KEYBOARD_KEY_70065=102nd
  '';

but none of them had any effect any effect.

Also, when I read the code:

https://github.com/NixOS/nixpkgs/blob/fb222e008681fce4608e94f2d1dfdf3d03a364c4/nixos/modules/services/hardware/udev.nix#L38

I see that a file is supposed to be created in /etc/udev/hwdb.d/99-local.hwdb but this file is not present in my case, but I'm not sure if this file is going to be merged into the bin file:

$ ls /etc/udev/
hwdb.bin  rules.d

Note that I may just have done something bad, I don't know, but I find it weird that even the above test fails while it was supposed to pass before.

Expected behavior

I expect remapping to work.

Notify maintainers

I don't see any maintainers, so I'll just ping random people that edited this file https://github.com/NixOS/nixpkgs/issues/127443 @rnhmjoj @flokli @shlevy @alyssais @dasJ sorry if you should not be ping

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result. Note that I my system is running 1ffba9f2f68 and I did the test on the latest unstable

rnhmjoj commented 2 years ago

I even tried to test the test-script proposed https://github.com/NixOS/nixpkgs/issues/127443 proposed

Did you check if the evdev name of the keyboard is correct? It may have changed since I've written that test.

In any case, I always recommend to use xkb to customise the layout: the syntax is clearer and device independent, also you don't have to rebuild the X server anymore after adding a new layout.

tobiasBora commented 2 years ago

Well it seems that the evdev has not changed:

image

Regarding xkb, I heard that xkb can't specify a rule specific to a specific device so it may not be good enough for my case, and some people reported conflicts with the Chinese layout in the above link. Also, I guess for some usecases (inputs not related to keyboards like foot pedals maybe?) udev mapping may be unavoidable (but I'm not an expert).

In any case this bug should be solved (either by fixing it, by documenting that it's broken… or by realizing that I did something stupid ^^).

rnhmjoj commented 2 years ago

Well, you already have a test and we know it used to work in the past, so bisecting nixpkgs will reveal what broke it.

Awan commented 2 years ago

@tobiasBora Did you reboot the machine? I just tried this and my custom keys are working... I have added a post as well on my blog...

How to remap keys

PanAeon commented 2 years ago

Well, nixos-rebuild definitely creates 99-local.hwdb with my config in the /nix/store. It just doesn't copy the result to the /etc...

Awan commented 2 years ago

@PanAeon you don't need something to be in /etc. Everything should be working without that.

Awan commented 2 years ago

@PanAeon check this asciiicast

PanAeon commented 2 years ago

@Awan yes, you are right! My problem was that I checked /dev/input/event5 instead of /dev/input/event4 because my mouse provided extra hardware buttons and I didn't notice that. I even disregarded my gut feeling that my mouse response has changed.:facepalm:

Still, this might be cosmetic issue?

Offtopic: @Awan , you might want to check kmonad for your keyboard configuration, it is much more flexible then plain udev rules.

Awan commented 2 years ago

I have been using many tools previously. You can check them in my old dotfiles repo but all those tools are somehow not useful. Like some tools are only working in X. So if you go to wayland, you have to find and configure another one. I like the way how nixos implements it. It even works in ttys...

On 12/08, PanAeon wrote: @.*** yes, you are right! My problem was that I checked /dev/input/event5 instead of /dev/input/event5 because my mouse provided extra hardware buttons and I didn't notice that. I even disregarded my gut feeling that my mouse response has changed.:facepalm:

Still, this might be cosmetic issue?

Offtopic: @Awan , you might want to check htps://github.com/kmonad/kmonad for your keyboard configuration, it is much more flexible then plain udev rules.

-- Reply to this email directly or view it on GitHub: https://github.com/NixOS/nixpkgs/issues/182966#issuecomment-1213511293 You are receiving this because you were mentioned.

Message ID: @.***>

Abdullah Khabir

Cyber Security Analyst

https://abdullah.today

C20F 2707 3025 2569 BAC5 534B 7820 6670 C19D 1580

Awan commented 2 years ago

You can check my note on how remapping works in nixos at https://abdullah.solutions On 12/08, PanAeon wrote: @.*** yes, you are right! My problem was that I checked /dev/input/event5 instead of /dev/input/event5 because my mouse provided extra hardware buttons and I didn't notice that. I even disregarded my gut feeling that my mouse response has changed.:facepalm:

Still, this might be cosmetic issue?

Offtopic: @Awan , you might want to check htps://github.com/kmonad/kmonad for your keyboard configuration, it is much more flexible then plain udev rules.

-- Reply to this email directly or view it on GitHub: https://github.com/NixOS/nixpkgs/issues/182966#issuecomment-1213511293 You are receiving this because you were mentioned.

Message ID: @.***>

Abdullah Khabir

Cyber Security Analyst

https://abdullah.today

C20F 2707 3025 2569 BAC5 534B 7820 6670 C19D 1580

tobiasBora commented 2 years ago

Thanks, I will try to reboot (I don't have my computer these days) but I was expecting it to work without reboot as some commands are automatically executed by NixOs (and I also manually executed them). Also any idea why the test fails? It should work as the machine boots from scratch, no?

PanAeon commented 2 years ago

@tobiasBora, well apparently you either need to reboot the machine or re-plug the device, or find which input event corresponds to your keyboard (using udevadm info) and trigger configuration change with sudo udevadm trigger /dev/input/eventXXX

My guess why the test failed is that keyboard name doesn't match evdev:name:AT Translated Set 2 keyboard:*.

Awan commented 1 year ago

I don't know why it is not working for you. A few days ago, I installed NixOS using flake which has this udev service and everything was working fine. still working. I'm thinking to remap my keys like I have backtick which with shift maps to tilda, I want it to be Insert key. Maybe I'll try it after configuring my locker service for river-session ;-)

On 13/08, Tobias Bora wrote:

Thanks, I will try to reboot (I don't Hg ave my computer these days) but I was expecting it to work without reboot as some commands are automatically executed by NixOs (and I also manually executed them). Also any idea why the test fails? It should work as the machine boots from scratch, no?

-- Reply to this email directly or view it on GitHub: https://github.com/NixOS/nixpkgs/issues/182966#issuecomment-1214152362 You are receiving this because you were mentioned.

Message ID: @.***>

Abdullah Khabir

Cyber Security Analyst

https://abdullah.today

C20F 2707 3025 2569 BAC5 534B 7820 6670 C19D 1580

tobiasBora commented 1 year ago

Hum that's really strange… I definitely rebooted many times, plugged/unplugged thousands of time… Maybe I'm doing something stupid but I have no idea how to debug this. @Awan is the test working on your laptop?

@PanAeon I tried to do udevadm info and I get:

$ udevadm info /dev/input/event10
P: /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/0003:045E:00DB.0008/input/input12/event10
N: input/event10
L: 0
S: input/by-path/pci-0000:00:14.0-usb-0:1.3.4:1.0-event-kbd
S: input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd
E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/0003:045E:00DB.0008/input/input12/event10
E: DEVNAME=/dev/input/event10
E: MAJOR=13
E: MINOR=74
E: SUBSYSTEM=input
E: USEC_INITIALIZED=166723864
E: PATH=/nix/store/l13pl299bca99ky4x1q8r5ackasn26qr-udev-path/bin:/nix/store/l13pl299bca99ky4x1q8r5ackasn26qr-udev-path/sbin
E: KEYBOARD_KEY_c022d=up
E: KEYBOARD_KEY_c022e=down
E: ID_INPUT=1
E: ID_INPUT_KEY=1
E: ID_INPUT_KEYBOARD=1
E: ID_VENDOR=Microsoft
E: ID_VENDOR_ENC=Microsoft
E: ID_VENDOR_ID=045e
E: ID_MODEL=Natural®_Ergonomic_Keyboard_4000
E: ID_MODEL_ENC=Natural®\x20Ergonomic\x20Keyboard\x204000
E: ID_MODEL_ID=00db
E: ID_REVISION=0173
E: ID_SERIAL=Microsoft_Natural®_Ergonomic_Keyboard_4000
E: ID_TYPE=hid
E: ID_BUS=usb
E: ID_USB_INTERFACES=:030101:030000:
E: ID_USB_INTERFACE_NUM=00
E: ID_USB_DRIVER=usbhid
E: ID_PATH=pci-0000:00:14.0-usb-0:1.3.4:1.0
E: ID_PATH_TAG=pci-0000_00_14_0-usb-0_1_3_4_1_0
E: LIBINPUT_DEVICE_GROUP=3/45e/db:usb-0000:00:14.0-1.3
E: DEVLINKS=/dev/input/by-path/pci-0000:00:14.0-usb-0:1.3.4:1.0-event-kbd /dev/input/by-id/usb-Microsoft_Natural®_Ergonomic_Keyboard_4000-event-kbd
E: TAGS=:power-switch:
E: CURRENT_TAGS=:power-switch:

But I don't know how to read it to see what is wrong with my config. I tried to change it as follows but still no luck:

  services.udev = {
    extraHwdb = ''
      keyboard:usb:v*p*
       KEYBOARD_KEY_70065=a
    '';
  };

Doing sudo udevadm trigger /dev/input/event10 just do nothing except that my screen blinks once and then my keyboard is back to the original layout (I use ibus to change my layout, not sure if it can be an issue here).

EDIT

@PanAeon regarding the name evdev:name:AT Translated Set 2 keyboard:* at least it appears in the list of devices as shown above in my screenshot… Would you recommend another name?

PanAeon commented 1 year ago

@tobiasBora Well, I guess your keyboard name is something like "Microsoft Natural® Ergonomic Keyboard 4000", not AT Translated Set 2 keyboard 😄 Please, use the name from udevadm info --attribute-walk /dev/input/event10 | grep 'ATTRS{name}'

tobiasBora commented 1 year ago

@PanAeon Oh but the AT Translated Set 2 * is only for the qemu test, that emulate the keyboard.

I don't have any {name} attribute…


Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/0003:045E:00DB.0008/input/input12/event10':
    KERNEL=="event10"
    SUBSYSTEM=="input"
    DRIVER==""
    ATTR{power/async}=="disabled"
    ATTR{power/control}=="auto"
    ATTR{power/runtime_active_kids}=="0"
    ATTR{power/runtime_active_time}=="0"
    ATTR{power/runtime_enabled}=="disabled"
    ATTR{power/runtime_status}=="unsupported"
    ATTR{power/runtime_suspended_time}=="0"
    ATTR{power/runtime_usage}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/0003:045E:00DB.0008/input/input12':
    KERNELS=="input12"
    SUBSYSTEMS=="input"
    DRIVERS==""
    ATTRS{capabilities/abs}=="0"
    ATTRS{capabilities/ev}=="120013"
    ATTRS{capabilities/ff}=="0"
    ATTRS{capabilities/key}=="1000000000007 ff800000000007ff febeffdff3cfffff fffffffffffffffe"
    ATTRS{capabilities/led}=="107"
    ATTRS{capabilities/msc}=="10"
    ATTRS{capabilities/rel}=="0"
    ATTRS{capabilities/snd}=="0"
    ATTRS{capabilities/sw}=="0"
    ATTRS{id/bustype}=="0003"
    ATTRS{id/product}=="00db"
    ATTRS{id/vendor}=="045e"
    ATTRS{id/version}=="0111"
    ATTRS{inhibited}=="0"
    ATTRS{phys}=="usb-0000:00:14.0-1.3.4/input0"
    ATTRS{power/async}=="disabled"
    ATTRS{power/control}=="auto"
    ATTRS{power/runtime_active_kids}=="0"
    ATTRS{power/runtime_active_time}=="0"
    ATTRS{power/runtime_enabled}=="disabled"
    ATTRS{power/runtime_status}=="unsupported"
    ATTRS{power/runtime_suspended_time}=="0"
    ATTRS{power/runtime_usage}=="0"
    ATTRS{properties}=="0"
    ATTRS{uniq}==""

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0/0003:045E:00DB.0008':
    KERNELS=="0003:045E:00DB.0008"
    SUBSYSTEMS=="hid"
    DRIVERS=="microsoft"
    ATTRS{country}=="00"
    ATTRS{power/async}=="enabled"
    ATTRS{power/control}=="auto"
    ATTRS{power/runtime_active_kids}=="0"
    ATTRS{power/runtime_active_time}=="0"
    ATTRS{power/runtime_enabled}=="disabled"
    ATTRS{power/runtime_status}=="unsupported"
    ATTRS{power/runtime_suspended_time}=="0"
    ATTRS{power/runtime_usage}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.3/1-1.3.4/1-1.3.4:1.0':
    KERNELS=="1-1.3.4:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="usbhid"
    ATTRS{authorized}=="1"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceClass}=="03"
    ATTRS{bInterfaceNumber}=="00"
    ATTRS{bInterfaceProtocol}=="01"
    ATTRS{bInterfaceSubClass}=="01"
    ATTRS{bNumEndpoints}=="01"
    ATTRS{power/async}=="enabled"
    ATTRS{power/runtime_active_kids}=="0"
    ATTRS{power/runtime_enabled}=="enabled"
    ATTRS{power/runtime_status}=="suspended"
    ATTRS{power/runtime_usage}=="0"
    ATTRS{supports_autosuspend}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.3/1-1.3.4':
    KERNELS=="1-1.3.4"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPacketSize0}=="8"
    ATTRS{bMaxPower}=="100mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 2"
    ATTRS{bcdDevice}=="0173"
    ATTRS{bmAttributes}=="a0"
    ATTRS{busnum}=="1"
    ATTRS{configuration}==""
    ATTRS{devnum}=="11"
    ATTRS{devpath}=="1.3.4"
    ATTRS{idProduct}=="00db"
    ATTRS{idVendor}=="045e"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Microsoft"
    ATTRS{maxchild}=="0"
    ATTRS{power/active_duration}=="12136130"
    ATTRS{power/async}=="enabled"
    ATTRS{power/autosuspend}=="2"
    ATTRS{power/autosuspend_delay_ms}=="2000"
    ATTRS{power/connected_duration}=="12136130"
    ATTRS{power/control}=="on"
    ATTRS{power/level}=="on"
    ATTRS{power/persist}=="1"
    ATTRS{power/runtime_active_kids}=="0"
    ATTRS{power/runtime_active_time}=="12135959"
    ATTRS{power/runtime_enabled}=="forbidden"
    ATTRS{power/runtime_status}=="active"
    ATTRS{power/runtime_suspended_time}=="0"
    ATTRS{power/runtime_usage}=="1"
    ATTRS{power/wakeup}=="enabled"
    ATTRS{power/wakeup_abort_count}=="0"
    ATTRS{power/wakeup_active}=="0"
    ATTRS{power/wakeup_active_count}=="0"
    ATTRS{power/wakeup_count}=="0"
    ATTRS{power/wakeup_expire_count}=="0"
    ATTRS{power/wakeup_last_time_ms}=="0"
    ATTRS{power/wakeup_max_time_ms}=="0"
    ATTRS{power/wakeup_total_time_ms}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="unknown"
    ATTRS{remove}=="(write-only)"
    ATTRS{rx_lanes}=="1"
    ATTRS{speed}=="1.5"
    ATTRS{tx_lanes}=="1"
    ATTRS{urbnum}=="14880"
    ATTRS{version}==" 2.00"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.3':
    KERNELS=="1-1.3"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceProtocol}=="02"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bcdDevice}=="0121"
    ATTRS{bmAttributes}=="e0"
    ATTRS{busnum}=="1"
    ATTRS{configuration}==""
    ATTRS{devnum}=="4"
    ATTRS{devpath}=="1.3"
    ATTRS{idProduct}=="0d6d"
    ATTRS{idVendor}=="03f0"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Microchip Tech"
    ATTRS{maxchild}=="4"
    ATTRS{power/active_duration}=="12137628"
    ATTRS{power/async}=="enabled"
    ATTRS{power/autosuspend}=="0"
    ATTRS{power/autosuspend_delay_ms}=="0"
    ATTRS{power/connected_duration}=="12137628"
    ATTRS{power/control}=="auto"
    ATTRS{power/level}=="auto"
    ATTRS{power/runtime_active_kids}=="3"
    ATTRS{power/runtime_active_time}=="12137463"
    ATTRS{power/runtime_enabled}=="enabled"
    ATTRS{power/runtime_status}=="active"
    ATTRS{power/runtime_suspended_time}=="0"
    ATTRS{power/runtime_usage}=="0"
    ATTRS{power/wakeup}=="disabled"
    ATTRS{power/wakeup_abort_count}==""
    ATTRS{power/wakeup_active}==""
    ATTRS{power/wakeup_active_count}==""
    ATTRS{power/wakeup_count}==""
    ATTRS{power/wakeup_expire_count}==""
    ATTRS{power/wakeup_last_time_ms}==""
    ATTRS{power/wakeup_max_time_ms}==""
    ATTRS{power/wakeup_total_time_ms}==""
    ATTRS{product}=="USB2734"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="fixed"
    ATTRS{remove}=="(write-only)"
    ATTRS{rx_lanes}=="1"
    ATTRS{speed}=="480"
    ATTRS{tx_lanes}=="1"
    ATTRS{urbnum}=="53"
    ATTRS{version}==" 2.10"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-1':
    KERNELS=="1-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceProtocol}=="02"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bcdDevice}=="0615"
    ATTRS{bmAttributes}=="e0"
    ATTRS{busnum}=="1"
    ATTRS{configuration}==""
    ATTRS{devnum}=="2"
    ATTRS{devpath}=="1"
    ATTRS{idProduct}=="0c6d"
    ATTRS{idVendor}=="03f0"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Microchip"
    ATTRS{maxchild}=="6"
    ATTRS{power/active_duration}=="12138239"
    ATTRS{power/async}=="enabled"
    ATTRS{power/autosuspend}=="0"
    ATTRS{power/autosuspend_delay_ms}=="0"
    ATTRS{power/connected_duration}=="12138239"
    ATTRS{power/control}=="auto"
    ATTRS{power/level}=="auto"
    ATTRS{power/runtime_active_kids}=="3"
    ATTRS{power/runtime_active_time}=="12137997"
    ATTRS{power/runtime_enabled}=="enabled"
    ATTRS{power/runtime_status}=="active"
    ATTRS{power/runtime_suspended_time}=="0"
    ATTRS{power/runtime_usage}=="0"
    ATTRS{power/wakeup}=="disabled"
    ATTRS{power/wakeup_abort_count}==""
    ATTRS{power/wakeup_active}==""
    ATTRS{power/wakeup_active_count}==""
    ATTRS{power/wakeup_count}==""
    ATTRS{power/wakeup_expire_count}==""
    ATTRS{power/wakeup_last_time_ms}==""
    ATTRS{power/wakeup_max_time_ms}==""
    ATTRS{power/wakeup_total_time_ms}==""
    ATTRS{product}=="USB2816 Smart Hub"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="removable"
    ATTRS{remove}=="(write-only)"
    ATTRS{rx_lanes}=="1"
    ATTRS{speed}=="480"
    ATTRS{tx_lanes}=="1"
    ATTRS{urbnum}=="548"
    ATTRS{version}==" 2.10"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1':
    KERNELS=="usb1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{authorized_default}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bcdDevice}=="0515"
    ATTRS{bmAttributes}=="e0"
    ATTRS{busnum}=="1"
    ATTRS{configuration}==""
    ATTRS{devnum}=="1"
    ATTRS{devpath}=="0"
    ATTRS{idProduct}=="0002"
    ATTRS{idVendor}=="1d6b"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Linux 5.15.34 xhci-hcd"
    ATTRS{maxchild}=="12"
    ATTRS{power/active_duration}=="12138366"
    ATTRS{power/async}=="enabled"
    ATTRS{power/autosuspend}=="0"
    ATTRS{power/autosuspend_delay_ms}=="0"
    ATTRS{power/connected_duration}=="12138366"
    ATTRS{power/control}=="auto"
    ATTRS{power/level}=="auto"
    ATTRS{power/runtime_active_kids}=="3"
    ATTRS{power/runtime_active_time}=="12138364"
    ATTRS{power/runtime_enabled}=="enabled"
    ATTRS{power/runtime_status}=="active"
    ATTRS{power/runtime_suspended_time}=="0"
    ATTRS{power/runtime_usage}=="0"
    ATTRS{power/wakeup}=="disabled"
    ATTRS{power/wakeup_abort_count}==""
    ATTRS{power/wakeup_active}==""
    ATTRS{power/wakeup_active_count}==""
    ATTRS{power/wakeup_count}==""
    ATTRS{power/wakeup_expire_count}==""
    ATTRS{power/wakeup_last_time_ms}==""
    ATTRS{power/wakeup_max_time_ms}==""
    ATTRS{power/wakeup_total_time_ms}==""
    ATTRS{product}=="xHCI Host Controller"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="unknown"
    ATTRS{remove}=="(write-only)"
    ATTRS{rx_lanes}=="1"
    ATTRS{serial}=="0000:00:14.0"
    ATTRS{speed}=="480"
    ATTRS{tx_lanes}=="1"
    ATTRS{urbnum}=="135"
    ATTRS{version}==" 2.00"

  looking at parent device '/devices/pci0000:00/0000:00:14.0':
    KERNELS=="0000:00:14.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="xhci_hcd"
    ATTRS{ari_enabled}=="0"
    ATTRS{broken_parity_status}=="0"
    ATTRS{class}=="0x0c0330"
    ATTRS{consistent_dma_mask_bits}=="64"
    ATTRS{d3cold_allowed}=="1"
    ATTRS{device}=="0x9ded"
    ATTRS{dma_mask_bits}=="64"
    ATTRS{driver_override}=="(null)"
    ATTRS{enable}=="1"
    ATTRS{index}=="5"
    ATTRS{irq}=="135"
    ATTRS{label}=="Onboard - Other"
    ATTRS{local_cpulist}=="0-7"
    ATTRS{local_cpus}=="ff"
    ATTRS{msi_bus}=="1"
    ATTRS{msi_irqs/135}=="msi"
    ATTRS{numa_node}=="-1"
    ATTRS{power/async}=="enabled"
    ATTRS{power/control}=="on"
    ATTRS{power/runtime_active_kids}=="1"
    ATTRS{power/runtime_active_time}=="12139191"
    ATTRS{power/runtime_enabled}=="forbidden"
    ATTRS{power/runtime_status}=="active"
    ATTRS{power/runtime_suspended_time}=="0"
    ATTRS{power/runtime_usage}=="1"
    ATTRS{power/wakeup}=="enabled"
    ATTRS{power/wakeup_abort_count}=="0"
    ATTRS{power/wakeup_active}=="0"
    ATTRS{power/wakeup_active_count}=="1"
    ATTRS{power/wakeup_count}=="0"
    ATTRS{power/wakeup_expire_count}=="1"
    ATTRS{power/wakeup_last_time_ms}=="173686"
    ATTRS{power/wakeup_max_time_ms}=="101"
    ATTRS{power/wakeup_total_time_ms}=="101"
    ATTRS{power_state}=="D0"
    ATTRS{remove}=="(write-only)"
    ATTRS{rescan}=="(write-only)"
    ATTRS{revision}=="0x30"
    ATTRS{subsystem_device}=="0x08b9"
    ATTRS{subsystem_vendor}=="0x1028"
    ATTRS{vendor}=="0x8086"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""
    ATTRS{power/async}=="enabled"
    ATTRS{power/control}=="auto"
    ATTRS{power/runtime_active_kids}=="19"
    ATTRS{power/runtime_active_time}=="0"
    ATTRS{power/runtime_enabled}=="disabled"
    ATTRS{power/runtime_status}=="unsupported"
    ATTRS{power/runtime_suspended_time}=="0"
    ATTRS{power/runtime_usage}=="0"
    ATTRS{waiting_for_supplier}=="0"
PanAeon commented 1 year ago

Well, maybe evdev didn't set a name then.... (I'm not an expert by any means). You can try creating a different rule based on the systemd example specifically rules, by which devices are matched:

# Supported hardware matches are:
#  - Generic input devices match:
#      evdev:input:bZZZZvYYYYpXXXXeWWWW-VVVV
#    This matches on the kernel modalias of the input-device, mainly:
#    ZZZZ is the bus-id (see /usr/include/linux/input.h BUS_*), YYYY, XXXX and
#    WWWW are the 4-digit hex uppercase vendor, product and version ID and VVVV
#    is an arbitrary length input-modalias describing the device capabilities.
#    The vendor, product and version ID for a device node "eventX" is listed
#    in /sys/class/input/eventX/device/id.
#
#  - AT keyboard DMI data matches:
#      evdev:atkbd:dmi:bvn*:bvr*:bd*:svn<vendor>:pn<product>:pvr*
#    <vendor> and <product> are the firmware-provided strings
#    exported by the kernel DMI modalias, see /sys/class/dmi/id/modalias
#
#  - Input driver device name and DMI data match:
#      evdev:name:<input device name>:dmi:bvn*:bvr*:bd*:svn<vendor>:pn*
#    <input device name> is the name device specified by the
#    driver, <vendor> is the firmware-provided string exported
#    by the kernel DMI modalias, see /sys/class/dmi/id/modalias
#
#  - Extended input driver device name, properties and DMI data match:
#      evdev:name:<input device name>:phys:<phys>:ev:<ev>:dmi:bvn*:bvr*:bd*:svn<vendor>:pn*
#    <input device name> is the name device specified by the
#    driver, <phys> is the physical-device-path, "cat
#    /sys/class/input/input?/phys", <ev> is the event bitmask, "cat
#    /sys/class/input/input?/capabilities/ev" and <vendor> is the
#    firmware-provided string exported by the kernel DMI modalias,
#    see /sys/class/dmi/id/modalias
PanAeon commented 1 year ago

@tobiasBora The test script is not correct. You need to disable virtio keyboard for it to work:

  nodes.machine = { pkgs, ... }:
    {
      documentation.enable = false;
      users.users.root.password = "";
      services.udev.extraHwdb =
        ''
          evdev:name:AT Translated Set 2 keyboard:*
           KEYBOARD_KEY_2c=x  # z -> x
           KEYBOARD_KEY_2d=z  # x -> z
        '';
      virtualisation.qemu.virtioKeyboard = false;
    };
tobiasBora commented 1 year ago

Whoo amazing! So it explains why the test fails now, the commit that introduces that is quite recent https://github.com/NixOS/nixpkgs/commit/56109be38bb159fe5dcb0dc7d8878577c69c9389 (I was actually bisecting to it but because of the fact that hydra does not build all commits it takes quite a long time to bisect it…)

Now I need to figure out why in my case it fails… I guess I will need to debug further my extraHwdb file ^^ (I find udev-stuff to be really hard to debug… finding the name of a device should not be that hard!)

QingyaoLin commented 1 year ago

Hi, I have the same question. Here is a link to my question from the nixos discussion.

nixos-discourse commented 7 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/keyboard-remaping-udevs-extrahwdbfile-not-taken-into-account/20576/3

nixos-discourse commented 7 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/customize-udev-hwdb-rules-not-working/25391/3