I’m currently migrating from my old Lenovo X230 (Ubuntu/i3 @Intel) to an new Lenovo P14s Gen2 (NixOS 21.05 /i3 @AMD Ryzen7).
NixOS Hw config is pulled from: <nixos-hardware/lenovo/thinkpad/p14s/amd/gen2>
One of the things which aren’t working out of the box are the “screen brightness” control keys (Fn+F5
& Fn+F6
).
On the old Ubuntu system I had set up event handling scripts in i3
for key codes XF86BrightnessUp
and XF86BrightnessDown
.
But this approach doesn’t work on the P14s / NixOS setup.
xev
doesn’t report those key codes on key press.
Question 1:
Does anybody has an idea why XF86BrightnessUp
and XF86BrightnessDown
aren’t recognised by xev
?
Any packages, drivers, kernel options that I’m missing?
Question 2:
I found a solution that I was able to adapt on NixOS. In my eyes as a newbie this looks a bit ugly / hackish.
Any suggestions to improve this nix-code?
{ config, pkgs, ... }:
let
p14s-backlight-inc = pkgs.writeShellScriptBin "backlight-increase" ''
bl_device=/sys/class/backlight/amdgpu_bl0/brightness
echo $(($(cat $bl_device)+10)) | tee $bl_device
'';
p14s-backlight-dec = pkgs.writeShellScriptBin "backlight-decrease" ''
bl_device=/sys/class/backlight/amdgpu_bl0/brightness
echo $(($(cat $bl_device)-10)) | tee $bl_device
'';
in {
environment.systemPackages = [
pkgs.acpid
p14s-backlight-inc
p14s-backlight-dec
];
services.acpid.handlers = {
"p14bl-inc" = {
action = "${p14s-backlight-inc}/bin/backlight-increase";
event = "video/brightnessup BRTUP 00000086 00000000";
};
"p14bl-dec" = {
action = "${p14s-backlight-dec}/bin/backlight-decrease";
event = "video/brightnessdown BRTDN 00000087 00000000";
};
};
}