mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-22 06:05:13 +00:00
29027fd1e1
Using pkgs.lib on the spine of module evaluation is problematic because the pkgs argument depends on the result of module evaluation. To prevent an infinite recursion, pkgs and some of the modules are evaluated twice, which is inefficient. Using ‘with lib’ prevents this problem.
66 lines
1.3 KiB
Nix
66 lines
1.3 KiB
Nix
# Upower daemon.
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
services.upower = {
|
|
|
|
enable = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = ''
|
|
Whether to enable Upower, a DBus service that provides power
|
|
management support to applications.
|
|
'';
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
###### implementation
|
|
|
|
config = mkIf config.services.upower.enable {
|
|
|
|
environment.systemPackages = [ pkgs.upower ];
|
|
|
|
services.dbus.packages = [ pkgs.upower ];
|
|
|
|
services.udev.packages = [ pkgs.upower ];
|
|
|
|
systemd.services.upower =
|
|
{ description = "Power Management Daemon";
|
|
path = [ pkgs.glib ]; # needed for gdbus
|
|
serviceConfig =
|
|
{ Type = "dbus";
|
|
BusName = "org.freedesktop.UPower";
|
|
ExecStart = "@${pkgs.upower}/libexec/upowerd upowerd";
|
|
};
|
|
};
|
|
|
|
system.activationScripts.upower =
|
|
''
|
|
mkdir -m 0755 -p /var/lib/upower
|
|
'';
|
|
|
|
# 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 =
|
|
''
|
|
${config.systemd.package}/bin/systemctl try-restart upower
|
|
'';
|
|
|
|
};
|
|
|
|
}
|