mirror of
				https://github.com/NixOS/nixos-hardware.git
				synced 2025-11-04 17:27:14 +08:00 
			
		
		
		
	Support reloading btusb module after resuming
This commit is contained in:
		
							
								
								
									
										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";
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user