3.4 KiB
Context
Currently, the system uses a default power management configuration. There is no easy way for the user to switch between different power-saving modes for different use cases, such as presenting, running a headless server, or normal desktop usage.
Goals / Non-Goals
Goals:
- Implement a script to control power management settings.
- Define three distinct power profiles:
caffeinated,headless, andnormal. - Integrate the script with Hyprland for key-based switching.
- Provide visual feedback of the current profile in the Waybar status bar.
- Manage the entire configuration using Nix and Home Manager.
Non-Goals:
- Creating a graphical user interface for configuration.
- Supporting operating systems other than NixOS.
- Supporting display managers other than Wayland/Hyprland.
Decisions
-
State Management: A state file at
~/.local/state/power-profilewill store the name of the currently active profile (e.g.,caffeinated). This simple approach allows the control script and Waybar module to easily share the current state. -
Control Script: A
bashscript will be the core of this feature. It will accept arguments likenext,prev, or a specific profile name (caffeinated,headless,normal). When called, it will: a. Update the state file. b. Kill any existinghypridleprocess. c. Start a newhypridleprocess with the configuration corresponding to the selected profile. d. Send a signal to Waybar to refresh the module (pkill -RTMIN+8 waybar). -
Power Management Daemon:
hypridlewill be used to manage idle events. We will define three separate service configurations for it, one for each profile, with different timeouts for screen blanking (hyprlock), and system suspension.- Caffeinated: No timeouts.
hypridlewill run with no events configured. - Headless: Timeout for screen blanking and locking, but no suspend action.
- Normal: Default timeouts for screen blanking, locking, and suspension.
- Caffeinated: No timeouts.
-
Waybar Module: A
custom/power-profilemodule in Waybar will be used.- It will use Waybar's
on-clickfunctionality to call the control script to cycle profiles. - It will execute a small script (
exec) that reads the state file and outputs JSON with an icon representing the current state (e.g.,{"text": "", "tooltip": "Profile: Caffeinated"}). - The module will update automatically when it receives a real-time signal, which the control script will send.
- It will use Waybar's
-
Hyprland Keybinding: A
bindentry inhyprland.confwill be added to call the control script to cycle through the profiles, e.g.,bind = $mainMod, BRACKETRIGHT, exec, ~/dotfiles/scripts/power-profile.sh next.
Risks / Trade-offs
-
[Risk] The
pkill hypridlecommand could potentially interfere with other user-startedhypridleinstances if they exist. -
Mitigation: This is unlikely in a typical user session. The script will be part of a managed dotfiles configuration where only one instance is expected.
-
Mitigation:
systemctl --user restart hypridle.serviceshould restart hypridle with new configuration -
[Trade-off] Using a state file on disk introduces a small amount of I/O and a potential point of failure if file permissions are incorrect.
-
Rationale: This is a simple and reliable IPC mechanism for this use case, preferable to more complex solutions. The file will be managed by Home Manager, ensuring correct permissions.