2024-09-08 19:22:14 -05:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2024-09-12 20:50:53 -05:00
|
|
|
with lib; let
|
2024-09-08 19:22:14 -05:00
|
|
|
grep = "${pkgs.gnugrep}/bin/grep";
|
2024-09-25 15:02:50 -05:00
|
|
|
hyprctl = "${config.programs.hyprland.package}/bin/hyprctl";
|
2024-09-08 19:22:14 -05:00
|
|
|
loginctl = "${pkgs.systemd}/bin/loginctl";
|
2024-12-24 09:26:54 -05:00
|
|
|
niri = "${config.programs.niri.package}/bin/niri";
|
2024-09-08 19:22:14 -05:00
|
|
|
pw-cli = "${pkgs.pipewire}/bin/pw-cli";
|
|
|
|
systemctl = "${pkgs.systemd}/bin/systemctl";
|
|
|
|
|
|
|
|
cfg = config.custom.services.hypridle;
|
2024-09-12 20:50:53 -05:00
|
|
|
in {
|
2024-12-30 10:08:25 -06:00
|
|
|
options.custom.services.hypridle = {
|
|
|
|
enable = mkOption {default = false;};
|
|
|
|
|
|
|
|
dpms = mkOption {
|
|
|
|
default =
|
|
|
|
if config.custom.desktop == "hyprland"
|
|
|
|
then "${hyprctl} dispatch dpms off"
|
|
|
|
else if config.custom.desktop == "niri"
|
|
|
|
then "${niri} msg action power-off-monitors"
|
|
|
|
else "";
|
|
|
|
};
|
|
|
|
};
|
2024-09-08 19:22:14 -05:00
|
|
|
|
|
|
|
config.home-manager.users.${config.custom.username} = mkIf cfg.enable {
|
|
|
|
# https://github.com/hyprwm/hypridle
|
|
|
|
# https://wiki.hyprland.org/Hypr-Ecosystem/hypridle
|
|
|
|
services.hypridle = {
|
|
|
|
enable = true;
|
|
|
|
|
2024-12-30 10:08:25 -06:00
|
|
|
settings.listener = [
|
|
|
|
{
|
|
|
|
timeout = 15 * 60; # Seconds
|
|
|
|
on-timeout = cfg.dpms;
|
|
|
|
}
|
2024-09-08 19:22:14 -05:00
|
|
|
|
2024-12-30 10:08:25 -06:00
|
|
|
{
|
|
|
|
timeout = 20 * 60; # Seconds
|
|
|
|
on-timeout = "${loginctl} lock-session";
|
|
|
|
}
|
2024-09-08 19:22:14 -05:00
|
|
|
|
2024-12-30 10:08:25 -06:00
|
|
|
{
|
|
|
|
timeout = 60 * 60; # Seconds
|
|
|
|
on-timeout = "${pw-cli} info all | ${grep} running || ${systemctl} suspend-then-hibernate"; # Suspend if no audio
|
|
|
|
}
|
|
|
|
];
|
2024-09-08 19:22:14 -05:00
|
|
|
};
|
2024-12-24 09:24:53 -05:00
|
|
|
|
|
|
|
# BUG: graphical-session-pre.target may not have WAYLAND_DISPLAY set, so service is skipped
|
|
|
|
# https://github.com/nix-community/home-manager/issues/5899
|
|
|
|
systemd.user.services.hypridle = {
|
|
|
|
Unit = {
|
|
|
|
After = mkForce ["graphical-session.target"]; # graphical-session-pre.target
|
|
|
|
};
|
|
|
|
};
|
2024-09-08 19:22:14 -05:00
|
|
|
};
|
|
|
|
}
|