Files
dotfiles/system-modules/health_reminder.nix
Lennart J. Kurzweg (Nx2) e4ec830aaa better health reminder
2024-11-21 22:07:53 +01:00

63 lines
2.1 KiB
Nix
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{ pkgs, lib, host, ... }:
lib.mkIf (host != "NxACE")
{
systemd.user.timers."health_reminder" = {
enable = true;
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "5m";
OnUnitActiveSec = "5m";
Unit = "health_reminder.service";
};
};
systemd.user.services."health_reminder" = let
hm = pkgs.writers.writePython3Bin "health_reminder" {
text = /*python*/ ''
import random
import re
class Action:
def __init__(self, action: str, likelihood: int, options: list[str] = None):
self.action = action
self.likelihood = likelihood
self.options = options if options is not None else []
def __str__(self):
try:
choice = random.choice(self.options)
except IndexError:
choice = ""
action = re.sub("%o", choice, self.action)
return action
actions = [
Action(action="look away for %o Seconds!", likelyhood=300, options=["10", "15"]),
Action(action="Posture Check!", likelyhood=300),
Action(action="Strech your upper body!", likelyhood=20),
Action(action="Strech your core!", likelyhood=10),
Action(action="Strech your legs!", likelyhood=10),
Action(action="Strech your arms/hands!", likelyhood=10),
Action(action="Make Tea!", likelyhood=5),
Action(action="", likelyhood=2),
]
total_likelihood = sum(a.likelihood for a in actions)
random_action = random.choices(actions, [a.likelihood for a in actions], k=1)[0]
print(random_action)
'';
};
in {
script = ''
set -eu
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$UID/bus"
${pkgs.libnotify}/bin/notify-send "$(${hm}/bin/health_reminder)"
'';
serviceConfig = {
Type = "oneshot";
User = "nx2";
};
};
}