2 { config, lib, pkgs, ... }:
5 cfg = config.services.upower;
17 enable = lib.mkOption {
18 type = lib.types.bool;
21 Whether to enable Upower, a DBus service that provides power
22 management support to applications.
26 package = lib.mkPackageOption pkgs "upower" { };
28 enableWattsUpPro = lib.mkOption {
29 type = lib.types.bool;
32 Enable the Watts Up Pro device.
34 The Watts Up Pro contains a generic FTDI USB device without a specific
35 vendor and product ID. When we probe for WUP devices, we can cause
36 the user to get a perplexing "Device or resource busy" error when
37 attempting to use their non-WUP device.
39 The generic FTDI device is known to also be used on:
41 - Sparkfun FT232 breakout board
46 noPollBatteries = lib.mkOption {
47 type = lib.types.bool;
50 Don't poll the kernel for battery level changes.
52 Some hardware will send us battery level changes through
53 events, rather than us having to poll for it. This option
54 allows disabling polling for hardware that sends out events.
58 ignoreLid = lib.mkOption {
59 type = lib.types.bool;
62 Do we ignore the lid state
64 Some laptops are broken. The lid state is either inverted, or stuck
65 on or off. We can't do much to fix these problems, but this is a way
66 for users to make the laptop panel vanish, a state that might be used
67 by a couple of user-space daemons. On Linux systems, see also
72 usePercentageForPolicy = lib.mkOption {
73 type = lib.types.bool;
76 Policy for warnings and action based on battery levels
78 Whether battery percentage based policy should be used. The default
79 is to use the percentage, which
80 should work around broken firmwares. It is also more reliable than
81 the time left (frantically saving all your files is going to use more
82 battery than letting it rest for example).
86 percentageLow = lib.mkOption {
87 type = lib.types.ints.unsigned;
90 When `usePercentageForPolicy` is
91 `true`, the levels at which UPower will consider the
94 This will also be used for batteries which don't have time information
95 such as that of peripherals.
97 If any value (of `percentageLow`,
98 `percentageCritical` and
99 `percentageAction`) is invalid, or not in descending
100 order, the defaults will be used.
104 percentageCritical = lib.mkOption {
105 type = lib.types.ints.unsigned;
108 When `usePercentageForPolicy` is
109 `true`, the levels at which UPower will consider the
112 This will also be used for batteries which don't have time information
113 such as that of peripherals.
115 If any value (of `percentageLow`,
116 `percentageCritical` and
117 `percentageAction`) is invalid, or not in descending
118 order, the defaults will be used.
122 percentageAction = lib.mkOption {
123 type = lib.types.ints.unsigned;
126 When `usePercentageForPolicy` is
127 `true`, the levels at which UPower will take action
128 for the critical battery level.
130 This will also be used for batteries which don't have time information
131 such as that of peripherals.
133 If any value (of `percentageLow`,
134 `percentageCritical` and
135 `percentageAction`) is invalid, or not in descending
136 order, the defaults will be used.
140 timeLow = lib.mkOption {
141 type = lib.types.ints.unsigned;
144 When `usePercentageForPolicy` is
145 `false`, the time remaining in seconds at which
146 UPower will consider the battery low.
148 If any value (of `timeLow`,
149 `timeCritical` and `timeAction`) is
150 invalid, or not in descending order, the defaults will be used.
154 timeCritical = lib.mkOption {
155 type = lib.types.ints.unsigned;
158 When `usePercentageForPolicy` is
159 `false`, the time remaining in seconds at which
160 UPower will consider the battery critical.
162 If any value (of `timeLow`,
163 `timeCritical` and `timeAction`) is
164 invalid, or not in descending order, the defaults will be used.
168 timeAction = lib.mkOption {
169 type = lib.types.ints.unsigned;
172 When `usePercentageForPolicy` is
173 `false`, the time remaining in seconds at which
174 UPower will take action for the critical battery level.
176 If any value (of `timeLow`,
177 `timeCritical` and `timeAction`) is
178 invalid, or not in descending order, the defaults will be used.
182 criticalPowerAction = lib.mkOption {
183 type = lib.types.enum [ "PowerOff" "Hibernate" "HybridSleep" ];
184 default = "HybridSleep";
186 The action to take when `timeAction` or
187 `percentageAction` has been reached for the batteries
188 (UPS or laptop batteries) supplying the computer
197 ###### implementation
199 config = lib.mkIf cfg.enable {
201 environment.systemPackages = [ cfg.package ];
203 services.dbus.packages = [ cfg.package ];
205 services.udev.packages = [ cfg.package ];
207 systemd.packages = [ cfg.package ];
209 environment.etc."UPower/UPower.conf".text = lib.generators.toINI {} {
211 EnableWattsUpPro = cfg.enableWattsUpPro;
212 NoPollBatteries = cfg.noPollBatteries;
213 IgnoreLid = cfg.ignoreLid;
214 UsePercentageForPolicy = cfg.usePercentageForPolicy;
215 PercentageLow = cfg.percentageLow;
216 PercentageCritical = cfg.percentageCritical;
217 PercentageAction = cfg.percentageAction;
218 TimeLow = cfg.timeLow;
219 TimeCritical = cfg.timeCritical;
220 TimeAction = cfg.timeAction;
221 CriticalPowerAction = cfg.criticalPowerAction;