From ddebede97439b73e1ba746c0ce68b999bcbb49c0 Mon Sep 17 00:00:00 2001 From: mexisme Date: Tue, 30 Jul 2024 16:54:07 +1200 Subject: [PATCH] On ASUS Zephyrus GA402X, make enabling auto-suspend on the keyboard optional - On kernels before 6.9.x, default to disabling auto-suspend - On more-recent kernels, default to enabling auto-suspend --- asus/zephyrus/ga402x/shared.nix | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/asus/zephyrus/ga402x/shared.nix b/asus/zephyrus/ga402x/shared.nix index 5049d6e..d4ca3fa 100644 --- a/asus/zephyrus/ga402x/shared.nix +++ b/asus/zephyrus/ga402x/shared.nix @@ -5,7 +5,11 @@ }: let - inherit (lib) mkDefault mkIf mkMerge version versionOlder; + inherit (lib) mkDefault mkEnableOption mkIf mkMerge version versionAtLeast versionOlder; + + cfg = config.hardware.asus.zephyrus.ga402x; + defaultAutosuspendEnable = if (versionAtLeast version "6.9") then true else false; + in { imports = [ @@ -18,6 +22,16 @@ in { ../../../common/pc/ssd ]; + options.hardware.asus.zephyrus.ga402x = { + # Kernels earlier than 6.9 (possibly even earlier) tend to take 1-2 key-presses + # to wake-up the internal keyboard after suspending (the ASUS N-KEY USB Device). + # + # Therefore, this option disables suspend for the keyboard by default, but + # enables it for kernel 6.9.x onwards. + keyboard.autosuspend.enable = (mkEnableOption "Enable auto-suspend on the internal USB keyboard (ASUS N-KEY Device) on Zephyrus GA402X" + ) // { default = defaultAutosuspendEnable; }; + }; + config = mkMerge [ { # Configure basic system settings: @@ -43,15 +57,20 @@ in { evdev:name:*:dmi:bvn*:bvr*:bd*:svnASUS*:pn*:* KEYBOARD_KEY_ff31007c=f20 ''; - extraRules = '' - # Disable auto-suspend for the ASUS N-KEY Device, i.e. USB Keyboard - # Otherwise, it will tend to take 1-2 key-presses to wake-up after suspending - ACTION=="add", SUBSYSTEM=="usb", TEST=="power/autosuspend", ATTR{idVendor}=="0b05", ATTR{idProduct}=="19b6", ATTR{power/autosuspend}="-1" - ''; }; }; } + (mkIf (! cfg.keyboard.autosuspend.enable) { + services.udev = { + extraRules = '' + # Disable auto-suspend for the ASUS N-KEY Device, i.e. USB Keyboard + # Otherwise on certain kernel-versions, it will tend to take 1-2 key-presses to wake-up after suspending + ACTION=="add", SUBSYSTEM=="usb", TEST=="power/autosuspend", ATTR{idVendor}=="0b05", ATTR{idProduct}=="19b6", ATTR{power/autosuspend}="-1" + ''; + }; + }) + (mkIf (versionOlder version "23.11") { # See https://asus-linux.org/wiki/nixos/ for info about some problems # detecting the dGPU: