Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upower: Upgrade to 1.90.6 and extend CriticalPowerActions #341086

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions nixos/modules/services/hardware/upower.nix
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,60 @@ 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`.
'';
};

};

};


###### 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 ];

Expand All @@ -218,6 +254,7 @@ in
TimeLow = cfg.timeLow;
TimeCritical = cfg.timeCritical;
TimeAction = cfg.timeAction;
AllowRiskyCriticalPowerAction = cfg.allowRiskyCriticalPowerAction;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, we should really switch to RFC 42-style settings so that we do not need to keep adding the options forever like this. Opened #341107 for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does indeed seem like better way of doing things.

CriticalPowerAction = cfg.criticalPowerAction;
};
};
Expand Down
6 changes: 4 additions & 2 deletions pkgs/by-name/up/upower/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
, libusb1
, glib
, gettext
, polkit
, nixosTests
, useIMobileDevice ? true
, libimobiledevice
Expand All @@ -34,7 +35,7 @@ assert withDocs -> withIntrospection;

stdenv.mkDerivation (finalAttrs: {
pname = "upower";
version = "1.90.4";
version = "1.90.6";

outputs = [ "out" "dev" ]
++ lib.optionals withDocs [ "devdoc" ]
Expand All @@ -45,7 +46,7 @@ stdenv.mkDerivation (finalAttrs: {
owner = "upower";
repo = "upower";
rev = "v${finalAttrs.version}";
hash = "sha256-5twHuDLisVF07Y5KYwlqWMi12+p6UpARJvoBN/+tX2o=";
hash = "sha256-Y3MIB6a11P00B/6E3UyoyjLLP8TIT3vM2FDO7zlBz/w=";
};

patches = lib.optionals (stdenv.hostPlatform.system == "i686-linux") [
Expand Down Expand Up @@ -90,6 +91,7 @@ stdenv.mkDerivation (finalAttrs: {
buildInputs = [
libgudev
libusb1
polkit
udev
] ++ lib.optionals withIntrospection [
# Duplicate from nativeCheckInputs until https://github.com/NixOS/nixpkgs/issues/161570 is solved
Expand Down