diff --git a/modules/config/power-management.nix b/modules/config/power-management.nix new file mode 100644 index 00000000000..a094caae0e0 --- /dev/null +++ b/modules/config/power-management.nix @@ -0,0 +1,63 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let + + cfg = config.powerManagement; + + sleepHook = pkgs.writeScript "sleep-hook.sh" + '' + #! ${pkgs.stdenv.shell} + action="$1" + if [ "$action" = "resume" ]; then + ${cfg.resumeCommands} + fi + ''; + +in + +{ + + ###### interface + + options = { + + powerManagement = { + + enable = mkOption { + default = false; + description = + '' + Whether to enable power management. This includes support + for suspend-to-RAM and powersave features on laptops. + ''; + }; + + resumeCommands = mkOption { + default = ""; + description = "Commands executed after the system resumes from suspend-to-RAM."; + }; + + }; + + }; + + + ###### implementation + + config = mkIf cfg.enable { + + # Enable the ACPI daemon. Not sure whether this is essential. + services.acpid.enable = true; + + environment.systemPackages = [ pkgs.pmutils ]; + + environment.etc = singleton + { source = sleepHook; + target = "pm/sleep.d/00sleep-hook"; + }; + + }; + +} diff --git a/modules/module-list.nix b/modules/module-list.nix index b69012f07e4..e3300242912 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -5,6 +5,7 @@ ./config/networking.nix ./config/no-x-libs.nix ./config/nsswitch.nix + ./config/power-management.nix ./config/system-path.nix ./config/timezone.nix ./config/unix-odbc-drivers.nix diff --git a/modules/services/hardware/acpid.nix b/modules/services/hardware/acpid.nix index 88bfc4e7258..e9fd8e46dc9 100644 --- a/modules/services/hardware/acpid.nix +++ b/modules/services/hardware/acpid.nix @@ -60,11 +60,11 @@ in options = { - powerManagement = { + services.acpid = { enable = mkOption { default = false; - description = "Whether to enable power management (ACPI daemon)"; + description = "Whether to enable the ACPI daemon."; }; }; @@ -74,7 +74,7 @@ in ###### implementation - config = mkIf config.powerManagement.enable { + config = mkIf config.services.acpid.enable { jobs.acpid = { description = "ACPI daemon"; diff --git a/modules/services/hardware/hal.nix b/modules/services/hardware/hal.nix index 6c033256633..25a24ce5e34 100644 --- a/modules/services/hardware/hal.nix +++ b/modules/services/hardware/hal.nix @@ -48,10 +48,9 @@ in config = mkIf cfg.enable { - # !!! move pmutils somewhere else - environment.systemPackages = [hal pkgs.pmutils]; + environment.systemPackages = [ hal ]; - services.hal.packages = [hal pkgs.hal_info]; + services.hal.packages = [ hal pkgs.hal_info ]; users.extraUsers = singleton { name = "haldaemon"; @@ -67,7 +66,7 @@ in jobs.hal = { description = "HAL daemon"; - startOn = "started dbus" + optionalString config.powerManagement.enable " and started acpid"; + startOn = "started dbus" + optionalString config.services.acpid.enable " and started acpid"; environment = { # !!! HACK? These environment variables manipulated inside @@ -113,4 +112,4 @@ in }; -} \ No newline at end of file +}