mirror of
				https://github.com/Stunkymonkey/nixos.git
				synced 2025-10-31 09:42:11 +01:00 
			
		
		
		
	hardware/action-on-low-power: init
	
		
			
	
		
	
	
		
	
		
			Some checks are pending
		
		
	
	
		
			
				
	
				/ Build Nix targets (push) Waiting to run
				
			
		
		
	
	
				
					
				
			
		
			Some checks are pending
		
		
	
	/ Build Nix targets (push) Waiting to run
				
			This commit is contained in:
		
							parent
							
								
									9dc05e7ea7
								
							
						
					
					
						commit
						c8fc9152fd
					
				
					 3 changed files with 47 additions and 0 deletions
				
			
		
							
								
								
									
										45
									
								
								modules/hardware/action-on-low-power/default.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								modules/hardware/action-on-low-power/default.nix
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,45 @@ | |||
| # low power action | ||||
| { | ||||
|   config, | ||||
|   lib, | ||||
|   options, | ||||
|   pkgs, | ||||
|   ... | ||||
| }: | ||||
| let | ||||
|   cfg = config.my.hardware.action-on-low-power; | ||||
| in | ||||
| { | ||||
|   options.my.hardware.action-on-low-power = { | ||||
|     enable = lib.mkEnableOption "action on low power"; | ||||
| 
 | ||||
|     action = lib.mkOption { | ||||
|       type = lib.types.enum [ | ||||
|         "hibernate" | ||||
|         "hybrid-sleep" | ||||
|         "poweroff" | ||||
|         "sleep" | ||||
|         "suspend-then-hibernate" | ||||
|         "suspend" | ||||
|       ]; | ||||
|       default = "sleep"; | ||||
|       description = '' | ||||
|         Action to take when power is low. | ||||
|       ''; | ||||
|     }; | ||||
| 
 | ||||
|     powerInPercent = lib.mkOption { | ||||
|       type = lib.types.int; | ||||
|       default = 10; | ||||
|       description = '' | ||||
|         Power percentage threshold to trigger the action. | ||||
|       ''; | ||||
|     }; | ||||
|   }; | ||||
| 
 | ||||
|   config = lib.mkIf cfg.enable { | ||||
|     services.udev.extraRules = '' | ||||
|       SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="${toString cfg.powerInPercent}", RUN+="${config.systemd.package}/bin/systemctl ${cfg.action}" | ||||
|     ''; | ||||
|   }; | ||||
| } | ||||
|  | @ -2,6 +2,7 @@ | |||
| { ... }: | ||||
| { | ||||
|   imports = [ | ||||
|     ./action-on-low-power | ||||
|     ./bluetooth | ||||
|     ./debug | ||||
|     ./drive-monitor | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Felix Buehler
						Felix Buehler