Hi,
I want to add a piece to my configuration.nix so that the keyboard layout changes when a USB keyboard is present, and I was wondering if there is a NixOS way of accomplishing this. Currently, I have:
services.udev.extraRules = ''
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="feed", ATTRS{idProduct}=="0000", RUN+="${pkgs.coreutils}/bin/touch /run/usb-keyboard-connected"
ACTION=="remove", SUBSYSTEM=="usb", ATTRS{idVendor}=="feed", ATTRS{idProduct}=="0000", RUN+="${pkgs.coreutils}/bin/rm /run/usb-keyboard-connected"
'';
systemd.services.usbKeyboardSwitch = {
description = "Switch keyboard layout based on external keyboard connection";
script = ''
#!/bin/sh
export DISPLAY=:0
while true; do
if [ -e /run/usb-keyboard-connected ]; then
/run/current-system/sw/bin/runuser -l microbass -c "/run/current-system/sw/bin/setxkbmap us"
else
/run/current-system/sw/bin/runuser -l microbass -c "/run/current-system/sw/bin/setxkbmap ie"
fi
sleep 10
done
'';
serviceConfig = {
Type = "simple";
Environment = "DISPLAY=:0 XAUTHORITY=/home/microbass/.Xauthority";
User = "microbass";
Group = "users";
Restart = "always";
RestartSec = "10";
};
wantedBy = [ "multi-user.target" ];
};
but I’m getting permission errors on the above. Is there an option that I’m missing to trigger setxkbmap in userspace?
Thanks, as always!