Support reloading btusb module after resuming
This commit is contained in:
parent
97900e1e7e
commit
0cee376703
40
dell/xps/sleep-resume/bluetooth/default.nix
Normal file
40
dell/xps/sleep-resume/bluetooth/default.nix
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
{config, lib, pkgs, ...}:
|
||||||
|
|
||||||
|
let
|
||||||
|
inherit (lib) mkIf mkOption types;
|
||||||
|
|
||||||
|
reloadBtusb = pkgs.writeShellApplication {
|
||||||
|
name = "reload-btusb.sh";
|
||||||
|
runtimeInputs = [
|
||||||
|
pkgs.coreutils
|
||||||
|
pkgs.kmod
|
||||||
|
];
|
||||||
|
text = ''
|
||||||
|
# Reload Bluetooth after resuming from sleep.
|
||||||
|
|
||||||
|
# Wait up-to 0.5 second for the module to be unloaded:
|
||||||
|
# (It should never take this long)
|
||||||
|
modprobe -r --wait 500 btusb
|
||||||
|
|
||||||
|
# "btusb" sometimes seems to need a little bit of time to settle after unloading:
|
||||||
|
sleep 0.2
|
||||||
|
modprobe btusb
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
cfg = config.services.sleep-resume.bluetooth;
|
||||||
|
in {
|
||||||
|
options = {
|
||||||
|
services.sleep-resume.bluetooth = {
|
||||||
|
enable = mkOption {
|
||||||
|
default = false;
|
||||||
|
type = types.bool;
|
||||||
|
description = "Reload Bluetooth after resuming from sleep";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
powerManagement.resumeCommands = "${reloadBtusb}/bin/reload-btusb.sh";
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue