dotfiles/modules/home/graphical/wayland/swayidle.nix
eriedaberrie f4565688f6 Initial commit
Note: not the actual initial commit.

I swear I will stop repeatedly force pushing to this single commit eventually
ok.
2024-09-25 09:49:53 -07:00

42 lines
1 KiB
Nix

{ pkgs, config, lib, osConfig, ... }:
let
cfg = config.my.graphical.wayland.swayidle;
in {
options.my.graphical.wayland.swayidle = {
enable = lib.mkEnableOption null // {
default = osConfig.my.laptop.enable;
};
lockCommand = lib.mkOption {
type = lib.types.str;
};
};
config = lib.mkIf cfg.enable {
services.swayidle = {
enable = true;
systemdTarget = "hyprland-session.target";
timeouts = let
inherit (pkgs) brightnessctl acpi gnugrep systemd;
withBat = command: "${acpi}/bin/acpi -b | ${gnugrep}/bin/grep -q 'Discharging' && ${command}";
in [
{
timeout = 60;
command = withBat "${brightnessctl}/bin/brightnessctl -s s 0";
resumeCommand = withBat "${brightnessctl}/bin/brightnessctl -r";
}
{
timeout = 300;
command = withBat "${systemd}/bin/systemctl suspend";
}
];
events = [
{
event = "before-sleep";
command = cfg.lockCommand;
}
];
};
};
}