nixos-config/hosts/grymforge/sleep.nix
gwg313 bb2fe56082
Some checks failed
Basic Code Checks / formatting-check (push) Has been cancelled
style
Signed-off-by: gwg313 <gwg313@pm.me>
2025-07-03 10:34:00 -04:00

34 lines
833 B
Nix

{ pkgs, ... }:
{
systemd.services.sleep-schedule = {
description = "Suspend PC at 10PM and wake at 6:30AM using rtcwake";
serviceConfig = {
Type = "oneshot";
ExecStart = pkgs.writeShellScript "sleep-schedule" ''
WAKE_TIME=$(${pkgs.coreutils}/bin/date +%s -d "tomorrow 06:30")
exec ${pkgs.util-linux}/bin/rtcwake -m mem -t "$WAKE_TIME"
'';
};
};
systemd.timers.sleep-schedule = {
description = "Timer to suspend PC at 10PM daily";
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "daily 22:00";
Persistent = true;
};
};
security.sudo.extraRules = [
{
users = [ "root" ];
commands = [
{
command = "/run/current-system/sw/bin/rtcwake";
options = [ "NOPASSWD" ];
}
];
}
];
}