nixos-config/config/programs/swayidle.nix

33 lines
1 KiB
Nix
Raw Normal View History

2022-06-12 15:39:15 +00:00
{pkgs, ...}: let
lock-script = pkgs.writeScript "suspend" ''
${pkgs.swaylock}/bin/swaylock -f -c 000000
${pkgs.mpc-cli}/bin/mpc pause
'';
screen-off-script = pkgs.writeScript "screenOff" ''
${pkgs.sway}/bin/swaymsg "output * dpms off"
'';
suspend-script = pkgs.writeScript "suspend" ''
${pkgs.systemd}/bin/systemctl suspend
'';
resume-script = pkgs.writeScript "resume" ''
${pkgs.sway}/bin/swaymsg "output * dpms on"
'';
unlock-script = pkgs.writeScript "unlock" ''
${pkgs.procps}/bin/pkill swaylock
${pkgs.mpc-cli}/bin/mpc play
'';
2022-06-12 15:39:15 +00:00
in {
systemd.user.services.swayidle = {
Unit = {
Description = "swayidle";
2022-06-12 15:39:15 +00:00
PartOf = ["graphical-session.target"];
};
Install = {
2022-06-12 15:39:15 +00:00
WantedBy = ["graphical-session.target"];
};
Service = {
ExecStart = "${pkgs.swayidle}/bin/swayidle -w timeout 300 ${lock-script} timeout 305 ${screen-off-script} resume ${resume-script} before-sleep ${lock-script} timeout 900 ${suspend-script} lock ${lock-script} unlock ${unlock-script}";
};
};
}