1
0
Fork 0
nixos-config/home-manager/roles/night-shutdown.nix

37 lines
1 KiB
Nix
Raw Normal View History

2022-03-08 01:42:46 +00:00
{pkgs, ...}: let
2022-01-20 01:49:52 +00:00
night-shutdown = pkgs.writeHaskellScript
2022-03-08 01:42:46 +00:00
{
name = "night-shutdown";
imports = [
"Data.Time.LocalTime"
"Data.Time.Format"
"Data.Time.Clock"
"Control.Concurrent"
"Data.Functor"
];
bins = [pkgs.libnotify pkgs.systemd];
} ''
2021-07-11 23:02:55 +00:00
interval = 5
2019-10-20 04:35:10 +00:00
main = forever $ do
time <- getZonedTime
let tod = localTimeOfDay . zonedTimeToLocalTime$ time
hour = todHour tod
2021-07-08 23:47:51 +00:00
minute = todMin tod
2021-07-08 23:42:07 +00:00
evening = hour == 0
2020-10-12 22:17:38 +00:00
night = (hour < 6 && hour >= 1)
2021-07-08 23:42:07 +00:00
action
| evening = notify_send "Shutdown alert!" ([i|Rechner fährt in #{59-minute} Minuten runter.|]::String)
2021-07-09 08:31:49 +00:00
| night = systemctl "poweroff"
2021-07-08 23:49:18 +00:00
| otherwise = pass
2021-07-08 23:42:07 +00:00
action
2021-07-11 23:02:55 +00:00
threadDelay $ (interval - (minute `mod` interval)) * 60 * 1000000
2019-07-31 21:56:52 +00:00
'';
2022-03-08 01:42:46 +00:00
in {
2022-01-20 01:49:52 +00:00
systemd.user.services.night-shutdown = {
Unit.Description = "Night Shutdown";
Service.ExecStart = "${night-shutdown}/bin/night-shutdown";
2022-03-08 01:42:46 +00:00
Install.WantedBy = ["graphical-session.target"];
2021-12-07 07:00:30 +00:00
};
2018-05-26 20:48:33 +00:00
}