kachick / dotfiles

๐Ÿคคโœ‚๐ŸŒณ
MIT License
13 stars 0 forks source link

Key remapping with udev always requires `sudo systemd-hwdb update && sudo udevadm trigger` after reboot #801

Closed kachick closed 1 month ago

kachick commented 1 month ago

https://github.com/kachick/dotfiles/issues/784 https://github.com/kachick/dotfiles/pull/786

:cry:

kachick commented 1 month ago

https://wiki.archlinux.jp/index.php/%E3%82%B9%E3%82%AD%E3%83%A3%E3%83%B3%E3%82%B3%E3%83%BC%E3%83%89%E3%82%92%E3%82%AD%E3%83%BC%E3%82%B3%E3%83%BC%E3%83%89%E3%81%AB%E3%83%9E%E3%83%83%E3%83%97

systemd-hwdb-update.service ใฎ ConditionNeedsUpdate ใ‚’ใ‚ณใƒกใƒณใƒˆใ‚ขใ‚ฆใƒˆใ™ใ‚‹ใจๅ†่ตทๅ‹•ใ™ใ‚‹ใŸใณใซ่‡ชๅ‹•็š„ใซๆ›ดๆ–ฐใ•ใ‚Œใพใ™:

kachick commented 1 month ago

https://github.com/NixOS/nixpkgs/blob/cf60e052431bb7289638e08bbf271eae2f8694dc/nixos/modules/system/boot/systemd.nix#L61-L62

kachick commented 1 month ago

https://github.com/NixOS/nixpkgs/blob/cf60e052431bb7289638e08bbf271eae2f8694dc/nixos/modules/services/hardware/udev.nix#L142-L162

kachick commented 1 month ago

https://github.com/NixOS/nixpkgs/blob/9133b9f5554437083a6618581eeae88c53593b0d/nixos/modules/system/boot/systemd/sysusers.nix#L120-L122

      services.systemd-sysusers = {
        # Enable switch-to-configuration to restart the service.
        unitConfig.ConditionNeedsUpdate = [ "" ];
kachick commented 1 month ago

https://github.com/NixOS/nixpkgs/blob/9133b9f5554437083a6618581eeae88c53593b0d/nixos/doc/manual/release-notes/rl-2305.section.md?plain=1#L268 https://github.com/systemd/systemd/pull/25714 https://github.com/NixOS/nixpkgs/blob/9133b9f5554437083a6618581eeae88c53593b0d/nixos/modules/services/hardware/udev.nix#L158


  hwdbBin = pkgs.runCommand "hwdb.bin"
    { preferLocalBuild = true;
      allowSubstitutes = false;
      packages = lib.unique (map toString ([udev] ++ cfg.packages));
    }
    ''
      mkdir -p etc/udev/hwdb.d
      for i in $packages; do
        echo "Adding hwdb files for package $i"
        for j in $i/{etc,lib}/udev/hwdb.d/*; do
          ln -s $j etc/udev/hwdb.d/$(basename $j)
        done
      done

      echo "Generating hwdb database..."
      # hwdb --update doesn't return error code even on errors!
      res="$(${pkgs.buildPackages.systemd}/bin/systemd-hwdb --root=$(pwd) update 2>&1)"
      echo "$res"
      [ -z "$(echo "$res" | egrep '^Error')" ]
      mv etc/udev/hwdb.bin $out
    '';
kachick commented 1 month ago

https://github.com/NixOS/nixpkgs/issues/308937 :eyes:

kachick commented 1 month ago
dotfiles main(0be7fe5)  direnv loaded/allowed via ๐Ÿน v1.22.6 1m26s via โ„๏ธ  impure (nix-shell-env) zsh 
> lat /etc/udev
0755 - 10-02 03:33 /etc/udev
0777 - 10-02 03:33 โ”œโ”€โ”€ rules.d -> /etc/static/udev/rules.d
0755 - 10-02 03:33 โ”œโ”€โ”€ hwdb.d
0777 - 10-02 03:33 โ”‚  โ”œโ”€โ”€ 98-keyboards.hwdb -> /etc/static/udev/hwdb.d/98-keyboards.hwdb
0777 - 10-02 03:33 โ”‚  โ””โ”€โ”€ 99-local.hwdb -> /etc/static/udev/hwdb.d/99-local.hwdb
0777 - 10-02 03:33 โ””โ”€โ”€ hwdb.bin -> /etc/static/udev/hwdb.bin

dotfiles main(0be7fe5)  direnv loaded/allowed via ๐Ÿน v1.22.6 via โ„๏ธ  impure (nix-shell-env) zsh 
> sudo systemd-hwdb update && sudo udevadm trigger

dotfiles main(0be7fe5)  direnv loaded/allowed via ๐Ÿน v1.22.6 via โ„๏ธ  impure (nix-shell-env) zsh 
> lat /etc/udev                            
0755   - 10-02 03:35 /etc/udev
0777   - 10-02 03:33 โ”œโ”€โ”€ rules.d -> /etc/static/udev/rules.d
0755   - 10-02 03:33 โ”œโ”€โ”€ hwdb.d
0777   - 10-02 03:33 โ”‚  โ”œโ”€โ”€ 98-keyboards.hwdb -> /etc/static/udev/hwdb.d/98-keyboards.hwdb
0777   - 10-02 03:33 โ”‚  โ””โ”€โ”€ 99-local.hwdb -> /etc/static/udev/hwdb.d/99-local.hwdb
0444 13M 10-02 03:35 โ””โ”€โ”€ hwdb.bin

systemd-hwdb update is actually replacing the symlink with binary.

The generated symlink by NixOS is not correct?

kachick commented 1 month ago

Once applied with sudo systemd-hwdb update && sudo udevadm trigger and sudo reboot now. the hwdb.bin will back to symlink. However in the state, it continue to work even thorough reboot again. So just adding the step after nixos-rebuild switch is enough for workaround. :thinking:

kachick commented 1 month ago

This problem looks still exists...

sudo reboot now. the hwdb.bin will back to symlink. However in the state, it continue to work even thorough reboot again.

Looks wrong

kachick commented 1 month ago

https://discourse.nixos.org/t/services-udev-extrahwdb-not-updating-99-local-rules/50849