From e4ad9ce38fa09e2f28ba15e830e17e367bf39a6c Mon Sep 17 00:00:00 2001 From: Adam Dinwoodie Date: Fri, 1 Nov 2024 17:51:53 +0000 Subject: [PATCH] Framework: add workaround for Bluetooth device issues Framework have published a workaround for a bug that affects the MediaTek Bluetooth and Wi-Fi cards used in their laptops on kernel version 6.11. Their workaround assumes a writable /etc/systemd directory, so reimplement the workaround for NixOS. For the Framework version of the workaround, see: https://github.com/FrameworkComputer/linux-docs/tree/eab0148ae8223eddaed8f0cd4cd73f9399ecdb65/hibernation/kernel-6-11-workarounds --- framework/13-inch/common/default.nix | 1 + framework/16-inch/common/default.nix | 1 + framework/bluetooth.nix | 37 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 framework/bluetooth.nix diff --git a/framework/13-inch/common/default.nix b/framework/13-inch/common/default.nix index 904c2d74..f9c78086 100644 --- a/framework/13-inch/common/default.nix +++ b/framework/13-inch/common/default.nix @@ -2,6 +2,7 @@ imports = [ ../../../common/pc/laptop ../../../common/pc/laptop/ssd + ../../bluetooth.nix ../../kmod.nix ../../framework-tool.nix ]; diff --git a/framework/16-inch/common/default.nix b/framework/16-inch/common/default.nix index 190956f5..5ec8a171 100644 --- a/framework/16-inch/common/default.nix +++ b/framework/16-inch/common/default.nix @@ -2,6 +2,7 @@ imports = [ ../../../common/pc/laptop ../../../common/pc/laptop/ssd + ../../bluetooth.nix ../../kmod.nix ../../framework-tool.nix ]; diff --git a/framework/bluetooth.nix b/framework/bluetooth.nix new file mode 100644 index 00000000..fdb7da3e --- /dev/null +++ b/framework/bluetooth.nix @@ -0,0 +1,37 @@ +# There is apparently a bug that affects Framework computers that causes black +# screen on resume from sleep or hibernate with kernel version 6.11. Framework +# have published a workaround; this applies that workaround. +# +# https://fosstodon.org/@frameworkcomputer/113406887743149089 +# https://github.com/FrameworkComputer/linux-docs/blob/main/hibernation/kernel-6-11-workarounds/suspend-hibernate-bluetooth-workaround.md#workaround-for-suspendhibernate-black-screen-on-resume-kernel-611 +{ + config, + lib, + pkgs, + ... +}: lib.mkIf ((config.boot.kernelPackages.kernelAtLeast "6.11") && (config.boot.kernelPackages.kernelOlder "6.12")) { + systemd.services = { + bluetooth-rfkill-suspend = { + description = "Soft block Bluetooth on suspend/hibernate"; + before = ["sleep.target"]; + unitConfig.StopWhenUnneeded = true; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${pkgs.util-linux}/bin/rfkill block bluetooth"; + ExecStartPost = "${pkgs.coreutils}/bin/sleep 3"; + RemainAfterExit = true; + }; + wantedBy = ["suspend.target" "hibernate.target" "suspend-then-hibernate.target"]; + }; + + bluetooth-rfkill-resume = { + description = "Unblock Bluetooth on resume"; + after = ["suspend.target" "hibernate.target" "suspend-then-hibernate.target"]; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${pkgs.util-linux}/bin/rfkill unblock bluetooth"; + }; + wantedBy = ["suspend.target" "hibernate.target" "suspend-then-hibernate.target"]; + }; + }; +}