diff --git a/system/options.nix b/system/options.nix index da435cfec867..92d17926add6 100644 --- a/system/options.nix +++ b/system/options.nix @@ -3033,7 +3033,20 @@ root ALL=(ALL) SETENV: ALL }; }; + + + powerManagement = { + + enable = mkOption { + default = false; + description = " + Whether to enable power management. + "; + }; + + }; + nesting = { children = mkOption { default = []; @@ -3043,6 +3056,7 @@ root ALL=(ALL) SETENV: ALL }; }; + passthru = mkOption { default = {}; description = " diff --git a/upstart-jobs/acpid.nix b/upstart-jobs/acpid.nix index efd608e13537..3a7df58bbafd 100644 --- a/upstart-jobs/acpid.nix +++ b/upstart-jobs/acpid.nix @@ -15,6 +15,9 @@ let event=button/lid.* action=${lidEventHandler} "%e" + + event=ac_adapter.* + action=${acEventHandler} "%e" ''; # Called when the power button is pressed. @@ -23,7 +26,6 @@ let #! ${pkgs.bash}/bin/sh # Suspend to RAM. #echo mem > /sys/power/state - exit 0 ''; # Called when the laptop lid is opened/closed. @@ -38,8 +40,18 @@ let sync echo mem > /sys/power/state fi + ''; - exit 0 + # Called when the AC power is connected or disconnected. + acEventHandler = pkgs.writeScript "ac-power.sh" + '' + #! ${pkgs.bash}/bin/sh + + if grep -q "state:.*on-line" /proc/acpi/ac_adapter/AC/state; then + echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + elif grep -q "state:.*off-line" /proc/acpi/ac_adapter/AC/state; then + echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + fi ''; in diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix index bd45dda49911..839769d028db 100644 --- a/upstart-jobs/default.nix +++ b/upstart-jobs/default.nix @@ -343,7 +343,7 @@ let }) # ACPI daemon. - ++ optional true /* !!! need some option */ + ++ optional config.powerManagement.enable (import ../upstart-jobs/acpid.nix { inherit config pkgs; })