Fixed suspending?

This commit is contained in:
Aleksandr Lebedev 2025-06-10 23:27:25 +02:00
parent dfe43b46e7
commit 14780764f9
2 changed files with 14 additions and 13 deletions

View file

@ -232,14 +232,15 @@
niri = lib.getExe config.programs.niri.package; niri = lib.getExe config.programs.niri.package;
loginctl = "${pkgs.systemd}/bin/loginctl"; loginctl = "${pkgs.systemd}/bin/loginctl";
locking-script = "pidof hyprlock || ${lib.getExe pkgs.hyprlock}"; locking-script = "pidof hyprlock || ${lib.getExe pkgs.hyprlock}";
systemctl = "${pkgs.systemd}/bin/systemctl";
#locking-script = "${pkgs.swaylock}/bin/swaylock --daemonize"; #locking-script = "${pkgs.swaylock}/bin/swaylock --daemonize";
#unlocking-script = "pkill -SIGUSR1 swaylock"; #unlocking-script = "pkill -SIGUSR1 swaylock";
suspendScript = pkgs.writeShellScript "suspend-script" '' suspendScript = cmd: pkgs.writeShellScript "suspend-script" ''
# check if any player has status "Playing" # check if any player has status "Playing"
${lib.getExe pkgs.playerctl} -a status | ${lib.getExe pkgs.ripgrep} Playing -q ${lib.getExe pkgs.playerctl} -a status | ${lib.getExe pkgs.ripgrep} Playing -q
# only suspend if nothing is playing # only suspend if nothing is playing
if [ $? == 1 ]; then if [ $? == 1 ]; then
${pkgs.systemd}/bin/systemctl suspend ${cmd}
fi fi
''; '';
in{ in{
@ -247,11 +248,11 @@ in{
events = [ events = [
{ {
event = "before-sleep"; event = "before-sleep";
command = "pidof hyprlock || ${loginctl} lock-session;${niri} msg action power-off-monitors"; command = "pidof hyprlock || ${loginctl} lock-session;#${niri} msg action power-off-monitors";
} }
{ {
event = "after-resume"; event = "after-resume";
command = "${niri} msg action power-on-monitors"; command = "#${niri} msg action power-on-monitors";
} }
{ {
event = "lock"; event = "lock";
@ -263,19 +264,21 @@ in{
#} #}
]; ];
timeouts = let timeouts = let
secondary = "${suspendScript}"; secondary = "${systemctl} suspend";
in[ in[
{ #{
timeout = 30; # timeout = 30;
command = "pidof hyprlock && ${secondary}"; # command = "pidof hyprlock && ${secondary}";
} #}
{ {
timeout = 300; timeout = 300;
command = "${locking-script}"; command = "${suspendScript ''${pkgs.libnotify}/bin/notify-send "You are idle. Going to sleep in 30 seconds"''}";
#command = "${locking-script}";
} }
{ {
timeout = 330; timeout = 330;
command = "pidof hyprlock && ${secondary}"; command = "${suspendScript "${systemctl} suspend"}";
#command = "pidof hyprlock && ${secondary}";
} }
]; ];
}; };

View file

@ -7,8 +7,6 @@
inputs.niri-flake.nixosModules.niri inputs.niri-flake.nixosModules.niri
]; ];
security.pam.services.hyprlock = {}; security.pam.services.hyprlock = {};
systemd.user.extraConfig = '' DefaultEnvironment="PATH=/run/wrappers/bin:/etc/profiles/per-user/%u/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:$PATH"
'';
programs.niri = { programs.niri = {
enable = true; enable = true;
package = pkgs.niri-unstable; package = pkgs.niri-unstable;