2011-07-25 01:45:52 +01:00
|
|
|
# Upower daemon.
|
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2011-07-25 01:45:52 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2011-07-25 01:45:52 +01:00
|
|
|
|
2014-05-19 12:13:32 +01:00
|
|
|
let
|
|
|
|
cfg = config.services.upower;
|
|
|
|
in
|
2011-07-25 01:45:52 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-07-25 01:45:52 +01:00
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-07-25 01:45:52 +01:00
|
|
|
services.upower = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-07-25 01:45:52 +01:00
|
|
|
enable = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.bool;
|
2011-07-25 01:45:52 +01:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable Upower, a DBus service that provides power
|
|
|
|
management support to applications.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-05-19 12:13:32 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.upower;
|
2016-01-17 18:34:55 +00:00
|
|
|
defaultText = "pkgs.upower";
|
2014-05-19 12:13:32 +01:00
|
|
|
example = lib.literalExample "pkgs.upower";
|
|
|
|
description = ''
|
|
|
|
Which upower package to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2011-07-25 01:45:52 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-07-25 01:45:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2014-05-19 12:13:32 +01:00
|
|
|
config = mkIf cfg.enable {
|
2011-07-25 01:45:52 +01:00
|
|
|
|
2014-05-19 12:13:32 +01:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2011-07-25 01:45:52 +01:00
|
|
|
|
2014-05-19 12:13:32 +01:00
|
|
|
services.dbus.packages = [ cfg.package ];
|
2011-07-25 01:45:52 +01:00
|
|
|
|
2014-05-19 12:13:32 +01:00
|
|
|
services.udev.packages = [ cfg.package ];
|
2011-08-24 22:24:39 +01:00
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
systemd.services.upower =
|
2012-10-04 21:38:31 +01:00
|
|
|
{ description = "Power Management Daemon";
|
2015-10-11 11:34:28 +01:00
|
|
|
path = [ pkgs.glib.out ]; # needed for gdbus
|
2012-10-04 21:38:31 +01:00
|
|
|
serviceConfig =
|
|
|
|
{ Type = "dbus";
|
|
|
|
BusName = "org.freedesktop.UPower";
|
2014-05-19 12:13:32 +01:00
|
|
|
ExecStart = "@${cfg.package}/libexec/upowerd upowerd";
|
2012-10-04 21:38:31 +01:00
|
|
|
};
|
|
|
|
};
|
2012-08-21 16:29:59 +01:00
|
|
|
|
2011-09-06 12:18:36 +01:00
|
|
|
system.activationScripts.upower =
|
|
|
|
''
|
|
|
|
mkdir -m 0755 -p /var/lib/upower
|
|
|
|
'';
|
|
|
|
|
2012-10-05 02:58:40 +01:00
|
|
|
# The upower daemon seems to get stuck after doing a suspend
|
|
|
|
# (i.e. subsequent suspend requests will say "Sleep has already
|
|
|
|
# been requested and is pending"). So as a workaround, restart
|
|
|
|
# the daemon.
|
|
|
|
powerManagement.resumeCommands =
|
|
|
|
''
|
2013-01-16 12:17:57 +00:00
|
|
|
${config.systemd.package}/bin/systemctl try-restart upower
|
2012-10-05 02:58:40 +01:00
|
|
|
'';
|
|
|
|
|
2011-07-25 01:45:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|