diff --git a/nixos/modules/services/hardware/upower.nix b/nixos/modules/services/hardware/upower.nix index 43604b17e8486..7b2ae8e8eee45 100644 --- a/nixos/modules/services/hardware/upower.nix +++ b/nixos/modules/services/hardware/upower.nix @@ -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; }; }; diff --git a/pkgs/by-name/up/upower/package.nix b/pkgs/by-name/up/upower/package.nix index 5f2321bb407f9..0f7dce691bccf 100644 --- a/pkgs/by-name/up/upower/package.nix +++ b/pkgs/by-name/up/upower/package.nix @@ -18,6 +18,7 @@ , libusb1 , glib , gettext +, polkit , nixosTests , useIMobileDevice ? true , libimobiledevice @@ -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" ] @@ -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") [ @@ -121,6 +122,7 @@ stdenv.mkDerivation (finalAttrs: { propagatedBuildInputs = [ glib + polkit ]; mesonFlags = [