2024-09-09 00:22:14 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2024-09-13 01:50:53 +00:00
|
|
|
with lib; let
|
2024-09-09 00:22:14 +00:00
|
|
|
grep = "${pkgs.gnugrep}/bin/grep";
|
2024-09-25 20:02:50 +00:00
|
|
|
hyprctl = "${config.programs.hyprland.package}/bin/hyprctl";
|
2024-12-22 12:15:58 +00:00
|
|
|
hyprlock = "${config.home-manager.users.${config.custom.username}.programs.hyprlock.package}/bin/hyprlock";
|
2024-09-09 00:22:14 +00:00
|
|
|
loginctl = "${pkgs.systemd}/bin/loginctl";
|
2024-12-24 14:26:54 +00:00
|
|
|
niri = "${config.programs.niri.package}/bin/niri";
|
2024-12-22 12:15:58 +00:00
|
|
|
pgrep = "${pkgs.procps}/bin/pgrep";
|
2024-09-09 00:22:14 +00:00
|
|
|
pw-cli = "${pkgs.pipewire}/bin/pw-cli";
|
|
|
|
systemctl = "${pkgs.systemd}/bin/systemctl";
|
|
|
|
|
|
|
|
cfg = config.custom.services.hypridle;
|
2024-09-13 01:50:53 +00:00
|
|
|
in {
|
|
|
|
options.custom.services.hypridle.enable = mkOption {default = false;};
|
2024-09-09 00:22:14 +00: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;
|
|
|
|
|
|
|
|
settings = {
|
|
|
|
general = {
|
|
|
|
before_sleep_cmd = "${pgrep} hyprlock || ${hyprlock} --immediate";
|
|
|
|
lock_cmd = "${pgrep} hyprlock || ${hyprlock}";
|
|
|
|
};
|
|
|
|
|
|
|
|
listener = [
|
|
|
|
{
|
|
|
|
timeout = 15 * 60; # Seconds
|
|
|
|
on-timeout = "${loginctl} lock-session";
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
timeout = 20 * 60; # Seconds
|
2024-12-24 14:26:54 +00:00
|
|
|
on-timeout =
|
|
|
|
if config.custom.desktops.desktop == "hyprland"
|
|
|
|
then "${hyprctl} dispatch dpms off"
|
|
|
|
else if config.custom.desktops.desktop == "niri"
|
|
|
|
then "${niri} msg action power-off-monitors"
|
|
|
|
else "";
|
2024-09-09 00:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
timeout = 60 * 60; # Seconds
|
|
|
|
on-timeout = "${pw-cli} info all | ${grep} running || ${systemctl} suspend-then-hibernate"; # Suspend if no audio
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2024-12-24 14:24:53 +00: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-09 00:22:14 +00:00
|
|
|
};
|
|
|
|
}
|