2011-07-25 02:45:52 +02:00
|
|
|
# Upower daemon.
|
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2011-07-25 02:45:52 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2011-07-25 02:45:52 +02:00
|
|
|
|
2014-05-19 13:13:32 +02:00
|
|
|
let
|
2019-09-08 11:03:46 +02:00
|
|
|
|
2014-05-19 13:13:32 +02:00
|
|
|
cfg = config.services.upower;
|
2019-09-08 11:03:46 +02:00
|
|
|
|
2014-05-19 13:13:32 +02:00
|
|
|
in
|
2019-09-08 11:03:46 +02:00
|
|
|
|
2011-07-25 02:45:52 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-07-25 02:45:52 +02:00
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-07-25 02:45:52 +02:00
|
|
|
services.upower = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-07-25 02:45:52 +02:00
|
|
|
enable = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
type = types.bool;
|
2011-07-25 02:45:52 +02:00
|
|
|
default = false;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2011-07-25 02:45:52 +02:00
|
|
|
Whether to enable Upower, a DBus service that provides power
|
|
|
|
management support to applications.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-11-27 01:19:27 +01:00
|
|
|
package = mkPackageOption pkgs "upower" { };
|
2014-05-19 13:13:32 +02:00
|
|
|
|
2019-11-23 09:07:06 +01:00
|
|
|
enableWattsUpPro = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-11-23 09:07:06 +01:00
|
|
|
Enable the Watts Up Pro device.
|
|
|
|
|
|
|
|
The Watts Up Pro contains a generic FTDI USB device without a specific
|
|
|
|
vendor and product ID. When we probe for WUP devices, we can cause
|
|
|
|
the user to get a perplexing "Device or resource busy" error when
|
|
|
|
attempting to use their non-WUP device.
|
|
|
|
|
|
|
|
The generic FTDI device is known to also be used on:
|
|
|
|
|
|
|
|
- Sparkfun FT232 breakout board
|
|
|
|
- Parallax Propeller
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
noPollBatteries = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-11-23 09:07:06 +01:00
|
|
|
Don't poll the kernel for battery level changes.
|
|
|
|
|
|
|
|
Some hardware will send us battery level changes through
|
|
|
|
events, rather than us having to poll for it. This option
|
|
|
|
allows disabling polling for hardware that sends out events.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
ignoreLid = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-11-23 09:07:06 +01:00
|
|
|
Do we ignore the lid state
|
|
|
|
|
|
|
|
Some laptops are broken. The lid state is either inverted, or stuck
|
|
|
|
on or off. We can't do much to fix these problems, but this is a way
|
|
|
|
for users to make the laptop panel vanish, a state that might be used
|
|
|
|
by a couple of user-space daemons. On Linux systems, see also
|
|
|
|
logind.conf(5).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
usePercentageForPolicy = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-11-23 09:07:06 +01:00
|
|
|
Policy for warnings and action based on battery levels
|
|
|
|
|
|
|
|
Whether battery percentage based policy should be used. The default
|
|
|
|
is to use the percentage, which
|
|
|
|
should work around broken firmwares. It is also more reliable than
|
|
|
|
the time left (frantically saving all your files is going to use more
|
|
|
|
battery than letting it rest for example).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
percentageLow = mkOption {
|
|
|
|
type = types.ints.unsigned;
|
|
|
|
default = 10;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-11-23 09:07:06 +01:00
|
|
|
When `usePercentageForPolicy` is
|
|
|
|
`true`, the levels at which UPower will consider the
|
|
|
|
battery low.
|
|
|
|
|
|
|
|
This will also be used for batteries which don't have time information
|
|
|
|
such as that of peripherals.
|
|
|
|
|
|
|
|
If any value (of `percentageLow`,
|
|
|
|
`percentageCritical` and
|
|
|
|
`percentageAction`) is invalid, or not in descending
|
|
|
|
order, the defaults will be used.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
percentageCritical = mkOption {
|
|
|
|
type = types.ints.unsigned;
|
|
|
|
default = 3;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-11-23 09:07:06 +01:00
|
|
|
When `usePercentageForPolicy` is
|
|
|
|
`true`, the levels at which UPower will consider the
|
|
|
|
battery critical.
|
|
|
|
|
|
|
|
This will also be used for batteries which don't have time information
|
|
|
|
such as that of peripherals.
|
|
|
|
|
|
|
|
If any value (of `percentageLow`,
|
|
|
|
`percentageCritical` and
|
|
|
|
`percentageAction`) is invalid, or not in descending
|
|
|
|
order, the defaults will be used.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
percentageAction = mkOption {
|
|
|
|
type = types.ints.unsigned;
|
|
|
|
default = 2;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-11-23 09:07:06 +01:00
|
|
|
When `usePercentageForPolicy` is
|
|
|
|
`true`, the levels at which UPower will take action
|
|
|
|
for the critical battery level.
|
|
|
|
|
|
|
|
This will also be used for batteries which don't have time information
|
|
|
|
such as that of peripherals.
|
|
|
|
|
|
|
|
If any value (of `percentageLow`,
|
|
|
|
`percentageCritical` and
|
|
|
|
`percentageAction`) is invalid, or not in descending
|
|
|
|
order, the defaults will be used.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
timeLow = mkOption {
|
|
|
|
type = types.ints.unsigned;
|
|
|
|
default = 1200;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-11-23 09:07:06 +01:00
|
|
|
When `usePercentageForPolicy` is
|
2021-09-03 01:10:09 +02:00
|
|
|
`false`, the time remaining in seconds at which
|
|
|
|
UPower will consider the battery low.
|
2019-11-23 09:07:06 +01:00
|
|
|
|
|
|
|
If any value (of `timeLow`,
|
|
|
|
`timeCritical` and `timeAction`) is
|
|
|
|
invalid, or not in descending order, the defaults will be used.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
timeCritical = mkOption {
|
|
|
|
type = types.ints.unsigned;
|
|
|
|
default = 300;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-11-23 09:07:06 +01:00
|
|
|
When `usePercentageForPolicy` is
|
2021-09-03 01:10:09 +02:00
|
|
|
`false`, the time remaining in seconds at which
|
|
|
|
UPower will consider the battery critical.
|
2019-11-23 09:07:06 +01:00
|
|
|
|
|
|
|
If any value (of `timeLow`,
|
|
|
|
`timeCritical` and `timeAction`) is
|
|
|
|
invalid, or not in descending order, the defaults will be used.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
timeAction = mkOption {
|
|
|
|
type = types.ints.unsigned;
|
|
|
|
default = 120;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-11-23 09:07:06 +01:00
|
|
|
When `usePercentageForPolicy` is
|
2021-09-03 01:10:09 +02:00
|
|
|
`false`, the time remaining in seconds at which
|
|
|
|
UPower will take action for the critical battery level.
|
2019-11-23 09:07:06 +01:00
|
|
|
|
|
|
|
If any value (of `timeLow`,
|
|
|
|
`timeCritical` and `timeAction`) is
|
|
|
|
invalid, or not in descending order, the defaults will be used.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
criticalPowerAction = mkOption {
|
|
|
|
type = types.enum [ "PowerOff" "Hibernate" "HybridSleep" ];
|
|
|
|
default = "HybridSleep";
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2019-11-23 09:07:06 +01:00
|
|
|
The action to take when `timeAction` or
|
|
|
|
`percentageAction` has been reached for the batteries
|
|
|
|
(UPS or laptop batteries) supplying the computer
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2011-07-25 02:45:52 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-07-25 02:45:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2014-05-19 13:13:32 +02:00
|
|
|
config = mkIf cfg.enable {
|
2011-07-25 02:45:52 +02:00
|
|
|
|
2014-05-19 13:13:32 +02:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2011-07-25 02:45:52 +02:00
|
|
|
|
2014-05-19 13:13:32 +02:00
|
|
|
services.dbus.packages = [ cfg.package ];
|
2011-07-25 02:45:52 +02:00
|
|
|
|
2014-05-19 13:13:32 +02:00
|
|
|
services.udev.packages = [ cfg.package ];
|
2011-08-24 23:24:39 +02:00
|
|
|
|
2019-09-08 11:03:46 +02:00
|
|
|
systemd.packages = [ cfg.package ];
|
|
|
|
|
2019-12-03 10:50:42 +01:00
|
|
|
environment.etc."UPower/UPower.conf".text = generators.toINI {} {
|
|
|
|
UPower = {
|
|
|
|
EnableWattsUpPro = cfg.enableWattsUpPro;
|
|
|
|
NoPollBatteries = cfg.noPollBatteries;
|
|
|
|
IgnoreLid = cfg.ignoreLid;
|
|
|
|
UsePercentageForPolicy = cfg.usePercentageForPolicy;
|
|
|
|
PercentageLow = cfg.percentageLow;
|
|
|
|
PercentageCritical = cfg.percentageCritical;
|
|
|
|
PercentageAction = cfg.percentageAction;
|
|
|
|
TimeLow = cfg.timeLow;
|
|
|
|
TimeCritical = cfg.timeCritical;
|
|
|
|
TimeAction = cfg.timeAction;
|
|
|
|
CriticalPowerAction = cfg.criticalPowerAction;
|
2019-11-23 09:07:06 +01:00
|
|
|
};
|
|
|
|
};
|
2011-07-25 02:45:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|