nixpkgs/modules/services/hardware/acpid.nix
Eelco Dolstra 1affc9168e * Move power management configuration into a separate module from
the acpid service.
* Add a pm-utils hook to allow commands to be executed when the system
  suspends/resumes etc.

svn path=/nixos/branches/upstart-0.6/; revision=18353
2009-11-15 12:48:42 +00:00

90 lines
1.6 KiB
Nix

{ config, pkgs, ... }:
with pkgs.lib;
let
acpiConfDir = pkgs.runCommand "acpi-events" {}
''
ensureDir $out
${
# Generate a .conf file for each event. (You can't have
# multiple events in one config file...)
let f = event:
''
fn=$out/${event.name}.conf
echo "event=${event.event}" > $fn
echo "action=${pkgs.writeScript "${event.name}.sh" event.action}" >> $fn
'';
in pkgs.lib.concatMapStrings f events
}
'';
events = [powerEvent lidEvent acEvent];
# Called when the power button is pressed.
powerEvent =
{ name = "power-button";
event = "button/power.*";
action =
''
#! ${pkgs.bash}/bin/sh
'';
};
# Called when the laptop lid is opened/closed.
lidEvent =
{ name = "lid";
event = "button/lid.*";
action =
''
#! ${pkgs.bash}/bin/sh
'';
};
# Called when the AC power is connected or disconnected.
acEvent =
{ name = "ac-power";
event = "ac_adapter.*";
action =
''
#! ${pkgs.bash}/bin/sh
'';
};
in
{
###### interface
options = {
services.acpid = {
enable = mkOption {
default = false;
description = "Whether to enable the ACPI daemon.";
};
};
};
###### implementation
config = mkIf config.services.acpid.enable {
jobs.acpid =
{ description = "ACPI daemon";
startOn = "started udev";
exec = "${pkgs.acpid}/sbin/acpid --foreground --confdir ${acpiConfDir}";
};
};
}