2020-04-24 23:36:52 +00:00
|
|
|
# Upower daemon.
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.upower;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.upower = {
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Whether to enable Upower, a DBus service that provides power
|
|
|
|
management support to applications.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
package = lib.mkPackageOption pkgs "upower" { };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
enableWattsUpPro = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00: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:
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
- Sparkfun FT232 breakout board
|
|
|
|
- Parallax Propeller
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
noPollBatteries = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00: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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
ignoreLid = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00: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).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
usePercentageForPolicy = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00: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).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
percentageLow = lib.mkOption {
|
|
|
|
type = lib.types.ints.unsigned;
|
2024-10-04 16:56:33 +00:00
|
|
|
default = 20;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
When `usePercentageForPolicy` is
|
|
|
|
`true`, the levels at which UPower will consider the
|
2020-04-24 23:36:52 +00:00
|
|
|
battery low.
|
|
|
|
|
|
|
|
This will also be used for batteries which don't have time information
|
|
|
|
such as that of peripherals.
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
If any value (of `percentageLow`,
|
|
|
|
`percentageCritical` and
|
|
|
|
`percentageAction`) is invalid, or not in descending
|
2020-04-24 23:36:52 +00:00
|
|
|
order, the defaults will be used.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
percentageCritical = lib.mkOption {
|
|
|
|
type = lib.types.ints.unsigned;
|
2024-10-04 16:56:33 +00:00
|
|
|
default = 5;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
When `usePercentageForPolicy` is
|
|
|
|
`true`, the levels at which UPower will consider the
|
2020-04-24 23:36:52 +00:00
|
|
|
battery critical.
|
|
|
|
|
|
|
|
This will also be used for batteries which don't have time information
|
|
|
|
such as that of peripherals.
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
If any value (of `percentageLow`,
|
|
|
|
`percentageCritical` and
|
|
|
|
`percentageAction`) is invalid, or not in descending
|
2020-04-24 23:36:52 +00:00
|
|
|
order, the defaults will be used.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
percentageAction = lib.mkOption {
|
|
|
|
type = lib.types.ints.unsigned;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 2;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
When `usePercentageForPolicy` is
|
|
|
|
`true`, the levels at which UPower will take action
|
2020-04-24 23:36:52 +00:00
|
|
|
for the critical battery level.
|
|
|
|
|
|
|
|
This will also be used for batteries which don't have time information
|
|
|
|
such as that of peripherals.
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
If any value (of `percentageLow`,
|
|
|
|
`percentageCritical` and
|
|
|
|
`percentageAction`) is invalid, or not in descending
|
2020-04-24 23:36:52 +00:00
|
|
|
order, the defaults will be used.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
timeLow = lib.mkOption {
|
|
|
|
type = lib.types.ints.unsigned;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 1200;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
When `usePercentageForPolicy` is
|
|
|
|
`false`, the time remaining in seconds at which
|
2022-02-10 20:34:41 +00:00
|
|
|
UPower will consider the battery low.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
If any value (of `timeLow`,
|
|
|
|
`timeCritical` and `timeAction`) is
|
2020-04-24 23:36:52 +00:00
|
|
|
invalid, or not in descending order, the defaults will be used.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
timeCritical = lib.mkOption {
|
|
|
|
type = lib.types.ints.unsigned;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 300;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
When `usePercentageForPolicy` is
|
|
|
|
`false`, the time remaining in seconds at which
|
2022-02-10 20:34:41 +00:00
|
|
|
UPower will consider the battery critical.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
If any value (of `timeLow`,
|
|
|
|
`timeCritical` and `timeAction`) is
|
2020-04-24 23:36:52 +00:00
|
|
|
invalid, or not in descending order, the defaults will be used.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
timeAction = lib.mkOption {
|
|
|
|
type = lib.types.ints.unsigned;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 120;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
When `usePercentageForPolicy` is
|
|
|
|
`false`, the time remaining in seconds at which
|
2022-02-10 20:34:41 +00:00
|
|
|
UPower will take action for the critical battery level.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
If any value (of `timeLow`,
|
|
|
|
`timeCritical` and `timeAction`) is
|
2020-04-24 23:36:52 +00:00
|
|
|
invalid, or not in descending order, the defaults will be used.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
criticalPowerAction = lib.mkOption {
|
|
|
|
type = lib.types.enum [ "PowerOff" "Hibernate" "HybridSleep" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "HybridSleep";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-08-12 12:06:08 +00:00
|
|
|
The action to take when `timeAction` or
|
|
|
|
`percentageAction` has been reached for the batteries
|
2020-04-24 23:36:52 +00:00
|
|
|
(UPS or laptop batteries) supplying the computer
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
services.dbus.packages = [ cfg.package ];
|
|
|
|
|
|
|
|
services.udev.packages = [ cfg.package ];
|
|
|
|
|
|
|
|
systemd.packages = [ cfg.package ];
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
environment.etc."UPower/UPower.conf".text = lib.generators.toINI {} {
|
2020-04-24 23:36:52 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|