mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
upower: Support Suspend and Ignore CriticalPowerActions
This commit is contained in:
parent
0bca21186b
commit
e81102472a
1 changed files with 40 additions and 3 deletions
|
@ -179,13 +179,31 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
allowRiskyCriticalPowerAction = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Enable the risky critical power actions "Suspend" and "Ignore".
|
||||
'';
|
||||
};
|
||||
|
||||
criticalPowerAction = lib.mkOption {
|
||||
type = lib.types.enum [ "PowerOff" "Hibernate" "HybridSleep" ];
|
||||
type = lib.types.enum [
|
||||
"PowerOff"
|
||||
"Hibernate"
|
||||
"HybridSleep"
|
||||
"Suspend"
|
||||
"Ignore"
|
||||
];
|
||||
default = "HybridSleep";
|
||||
description = ''
|
||||
The action to take when `timeAction` or
|
||||
`percentageAction` has been reached for the batteries
|
||||
(UPS or laptop batteries) supplying the computer
|
||||
(UPS or laptop batteries) supplying the computer.
|
||||
|
||||
When set to `Suspend` or `Ignore`,
|
||||
{option}`services.upower.allowRiskyCriticalPowerAction` must be set
|
||||
to `true`.
|
||||
'';
|
||||
};
|
||||
|
||||
|
@ -193,10 +211,28 @@ in
|
|||
|
||||
};
|
||||
|
||||
|
||||
###### implementation
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
assertions = [
|
||||
{
|
||||
assertion =
|
||||
let
|
||||
inherit (builtins) elem;
|
||||
riskyActions = [
|
||||
"Suspend"
|
||||
"Ignore"
|
||||
];
|
||||
riskyActionEnabled = elem cfg.criticalPowerAction riskyActions;
|
||||
in
|
||||
riskyActionEnabled -> cfg.allowRiskyCriticalPowerAction;
|
||||
message = ''
|
||||
services.upower.allowRiskyCriticalPowerAction must be true if
|
||||
services.upower.criticalPowerAction is set to
|
||||
'${cfg.criticalPowerAction}'.
|
||||
'';
|
||||
}
|
||||
];
|
||||
|
||||
environment.systemPackages = [ cfg.package ];
|
||||
|
||||
|
@ -218,6 +254,7 @@ in
|
|||
TimeLow = cfg.timeLow;
|
||||
TimeCritical = cfg.timeCritical;
|
||||
TimeAction = cfg.timeAction;
|
||||
AllowRiskyCriticalPowerAction = cfg.allowRiskyCriticalPowerAction;
|
||||
CriticalPowerAction = cfg.criticalPowerAction;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue