diff --git a/system/options.nix b/system/options.nix index 6b0f725ab2f..6e165c3b00a 100644 --- a/system/options.nix +++ b/system/options.nix @@ -2186,7 +2186,20 @@ in }; }; + + + powerManagement = { + + enable = mkOption { + default = false; + description = " + Whether to enable power management. + "; + }; + + }; + nesting = { children = mkOption { default = []; @@ -2196,6 +2209,7 @@ in }; }; + passthru = mkOption { default = {}; description = " diff --git a/upstart-jobs/acpid.nix b/upstart-jobs/acpid.nix index efd608e1353..3a7df58bbaf 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 9fb19188581..ea5d8fcdbe0 100644 --- a/upstart-jobs/default.nix +++ b/upstart-jobs/default.nix @@ -361,7 +361,7 @@ let }) # ACPI daemon. - ++ optional true /* !!! need some option */ + ++ optional config.powerManagement.enable (import ../upstart-jobs/acpid.nix { inherit config pkgs; })