From 15d9ec616a5b046fb6983947e973f11f430a0499 Mon Sep 17 00:00:00 2001 From: Johannes Arnold Date: Sun, 25 May 2025 22:16:35 +0200 Subject: [PATCH] nixos/tuxedo-drivers: add optional udev parameters --- nixos/modules/hardware/tuxedo-drivers.nix | 77 ++++++++++++++++++++++- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/nixos/modules/hardware/tuxedo-drivers.nix b/nixos/modules/hardware/tuxedo-drivers.nix index 154eb09fc895..f53e1297f137 100644 --- a/nixos/modules/hardware/tuxedo-drivers.nix +++ b/nixos/modules/hardware/tuxedo-drivers.nix @@ -1,7 +1,25 @@ -{ config, lib, ... }: +{ + config, + lib, + pkgs, + ... +}: let cfg = config.hardware.tuxedo-drivers; tuxedo-drivers = config.boot.kernelPackages.tuxedo-drivers; + udevRule = + attr: val: + let + # Workaround to evaluate true to "1" and false to "0". + # Otherwise, true evaluates to "1" and false to "". + newVal = if lib.isBool val then (if val then "1" else "0") else val; + in + lib.concatStringsSep ", " [ + ''SUBSYSTEM=="platform"'' + ''DRIVER=="tuxedo_keyboard"'' + ''ATTR{${attr}}="${newVal}"'' + ]; + optUdevRule = attr: val: lib.optional (val != null) (udevRule attr val); in { imports = [ @@ -26,11 +44,66 @@ in For more inforation it is best to check at the source code description: ''; + settings = { + charging-profile = lib.mkOption { + type = lib.types.nullOr ( + lib.types.enum [ + "high_capacity" + "balanced" + "stationary" + ] + ); + default = null; + description = '' + The maximum charge level to help reduce battery wear: + - `high_capacity` charges to 100% (driver default) + - `balanced` charges to 90% + - `stationary` charges to 80% (maximum lifespan) + + **Note:** Regardless of the configured charging profile, the operating system will always report the battery as being charged to 100%. + ''; + }; + charging-priority = lib.mkOption { + type = lib.types.nullOr ( + lib.types.enum [ + "charge_battery" + "performance" + ] + ); + default = null; + description = '' + These options manage the trade-off between battery charging and CPU performance when the USB-C power supply cannot provide sufficient power for both simultaneously: + - `charge_battery` prioritizes battery charging (driver default) + - `performance` prioritizes maximum CPU performance + ''; + }; + fn-lock = lib.mkOption { + type = lib.types.nullOr lib.types.bool; + default = null; + description = '' + Enables or disables the laptop keyboard's Function (Fn) lock at boot. + + When set to `true`, the Fn lock is enabled, allowing the function keys (F1–F12) to control brightness, volume etc. + ''; + }; + }; }; config = lib.mkIf cfg.enable { boot.kernelModules = [ "tuxedo_keyboard" ]; boot.extraModulePackages = [ tuxedo-drivers ]; - services.udev.packages = [ tuxedo-drivers ]; + services.udev.packages = [ + tuxedo-drivers + lib.mkIf + (lib.any (v: v != null) cfg.settings) + (pkgs.writeTextDir "etc/udev/rules.d/90-tuxedo.rules" ( + lib.concatLines ( + [ "# Custom rules for TUXEDO laptops" ] + ++ (optUdevRule "charging_profile/charging_profile" cfg.settings.charging-profile) + ++ (optUdevRule "charging_priority/charging_prio" cfg.settings.charging-priority) + ++ (optUdevRule "fn_lock" cfg.settings.fn-lock) + ) + )) + ]; }; }