From 1c43b4946b6c4fd121a5a1c650d81aabaa8340ef Mon Sep 17 00:00:00 2001 From: Marc Weber Date: Fri, 6 Mar 2009 12:25:25 +0000 Subject: [PATCH] Convert "acpid" svn path=/nixos/branches/fix-style/; revision=14358 --- system/options.nix | 14 ++--------- upstart-jobs/acpid.nix | 56 +++++++++++++++++++++++++++++------------- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/system/options.nix b/system/options.nix index af2801c83d07..1b924accb5df 100644 --- a/system/options.nix +++ b/system/options.nix @@ -2180,18 +2180,6 @@ in }; - powerManagement = { - - enable = mkOption { - default = false; - description = " - Whether to enable power management. - "; - }; - - }; - - nesting = { children = mkOption { default = []; @@ -2222,6 +2210,8 @@ in (import ../system/activate-configuration.nix) (import ../upstart-jobs/default.nix) + (import ../upstart-jobs/acpid.nix) # ACPI daemon + # security (import ../system/sudo.nix) diff --git a/upstart-jobs/acpid.nix b/upstart-jobs/acpid.nix index e2eb702bcd43..5ab724b431c4 100644 --- a/upstart-jobs/acpid.nix +++ b/upstart-jobs/acpid.nix @@ -1,5 +1,22 @@ {pkgs, config, ...}: +###### interface +let + inherit (pkgs.lib) mkOption mkIf; + + options = { + powerManagement = { + + enable = mkOption { + default = false; + description = "Whether to enable power management (ACPI daemon)"; + }; + }; + }; +in + +###### implementation + let acpiConfDir = pkgs.runCommand "acpi-events" {} @@ -17,9 +34,7 @@ let in pkgs.lib.concatMapStrings f events } ''; - - events = [powerEvent lidEvent acEvent]; - + # Called when the power button is pressed. powerEvent = { name = "power-button"; @@ -29,7 +44,7 @@ let #! ${pkgs.bash}/bin/sh ''; }; - + # Called when the laptop lid is opened/closed. lidEvent = { name = "lid"; @@ -47,7 +62,7 @@ let fi ''; }; - + # Called when the AC power is connected or disconnected. acEvent = { name = "ac-power"; @@ -64,20 +79,27 @@ let ''; }; + events = [powerEvent lidEvent acEvent]; + in -{ - name = "acpid"; - - extraPath = [pkgs.acpid]; - - job = '' - description "ACPI daemon" +mkIf config.powerManagement.enable { + require = [ + options + ]; - start on udev - stop on shutdown + services = { + extraJobs = [{ + name = "acpid"; - respawn ${pkgs.acpid}/sbin/acpid --foreground --confdir ${acpiConfDir} - ''; - + job = '' + description "ACPI daemon" + + start on udev + stop on shutdown + + respawn ${pkgs.acpid}/sbin/acpid --foreground --confdir ${acpiConfDir} + ''; + }]; + }; }