From c4a6d8c740c9ed404b0fa4df16eabb8be58324fe Mon Sep 17 00:00:00 2001 From: Thomas Woolford Date: Wed, 15 Jul 2026 13:00:12 +0930 Subject: [PATCH] Add Keylightd package and module, make available to fw13 and fw16 --- framework/13-inch/common/default.nix | 1 + framework/16-inch/common/default.nix | 1 + framework/keylightd.nix | 76 ++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 framework/keylightd.nix diff --git a/framework/13-inch/common/default.nix b/framework/13-inch/common/default.nix index eee10155a..f53f5db52 100644 --- a/framework/13-inch/common/default.nix +++ b/framework/13-inch/common/default.nix @@ -5,6 +5,7 @@ ../../../common/pc/ssd ../../kmod.nix ../../framework-tool.nix + ../../keylightd.nix ./classic-audio.nix ]; diff --git a/framework/16-inch/common/default.nix b/framework/16-inch/common/default.nix index 44f867f99..182f33909 100644 --- a/framework/16-inch/common/default.nix +++ b/framework/16-inch/common/default.nix @@ -5,6 +5,7 @@ ../../../common/pc/ssd ../../kmod.nix ../../framework-tool.nix + ../../keylightd.nix ]; # For fingerprint support diff --git a/framework/keylightd.nix b/framework/keylightd.nix new file mode 100644 index 000000000..07d61a239 --- /dev/null +++ b/framework/keylightd.nix @@ -0,0 +1,76 @@ +{ + pkgs, + config, + lib, + ... +}: +let + cfg = config.services.hardware.keylightd; + rustPlatform = pkgs.rustPlatform; + source = pkgs.fetchFromGitHub { + owner = "jonas-schievink"; + repo = "keylightd"; + rev = "b7b17e3ac9402cbaac9ca9192c33755f6e8394a6"; # PR#3 that fixes build + sha256 = "sha256-QFsbd3npKQkiNuv9xxU0erKClbDACiu8fg7NNecsqz8="; + }; + cargoToml = builtins.fromTOML (builtins.readFile "${source}/Cargo.toml"); + package = rustPlatform.buildRustPackage { + pname = "keylightd"; + version = cargoToml.package.version; + src = source; + cargoLock = { + lockFile = "${source}/Cargo.lock"; + }; + buildInputs = with pkgs; [ libevdev ]; + meta = with lib; { + description = "A keyboard backlight daemon for Framework laptops"; + license = licenses.bsd0; + platforms = platforms.linux; + mainProgram = "keylightd"; + }; + }; + +in +{ + options = with lib; { + services.hardware.keylightd = { + enable = mkEnableOption "keylightd"; + package = mkOption { + type = types.package; + default = package; + description = "The keylightd package to use."; + }; + brightness = mkOption { + type = types.int; + default = 30; + description = "The default brightness of the keyboard backlight (0-100)."; + }; + timeout = mkOption { + type = types.int; + default = 10; + description = "The timeout in seconds after which the keyboard backlight will turn off."; + }; + powerLight = mkOption { + type = types.bool; + default = true; + description = "Whether to control the power light on the keyboard."; + }; + }; + }; + config = lib.mkIf cfg.enable { + systemd.services.keylightd = { + description = "Keyboard backlight daemon for Framework laptops"; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Type = "exec"; + ExecStart = + lib.getExe cfg.package + + " --brightness ${toString cfg.brightness}" + + " --timeout ${toString cfg.timeout}" + + lib.optionalString cfg.powerLight " --power"; + Restart = "on-failure"; + RestartSec = "1s"; + }; + }; + }; +}