1
0
Fork 0
nixos-config/home-manager/roles/sleep-nag.nix

39 lines
1 KiB
Nix
Raw Normal View History

2020-05-27 13:20:08 +00:00
{ pkgs, ... }:
2018-05-26 20:48:33 +00:00
let
2021-05-18 14:33:28 +00:00
sleep-nag = pkgs.writeHaskellScript
{
name = "sleep-nag";
imports = [
"Data.Time.LocalTime"
"Data.Time.Format"
"Data.Time.Clock"
"Control.Concurrent"
"Data.Functor"
];
2021-07-09 08:31:49 +00:00
bins = [ pkgs.libnotify pkgs.systemd ];
2021-05-18 14:33:28 +00:00
} ''
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
'';
2021-05-18 14:33:28 +00:00
in
{
2021-12-03 00:13:50 +00:00
#systemd.user.services.sleep-nag = {
# Unit.Description = "Sleep nag";
# Service.ExecStart = "${sleep-nag}/bin/sleep-nag";
# Install.WantedBy = [ "graphical-session.target" ];
#};
2018-05-26 20:48:33 +00:00
}