1{
2 pkgs,
3 config,
4 ...
5}: let
6 notifyOnUnplugScript = ''
7 #!${pkgs.bash}/bin/bash
8 LOGIN=$(cat "${config.age.secrets.ntfyAuto.path}")
9
10 ${pkgs.curl}/bin/curl -u $LOGIN \
11 -H "X-Priority: 5" \
12 -d "ME YOUR CHILD ${config.networking.hostName} WAS UNPLUGGED FROM THE CHARGER HELP ME" \
13 https://${config.mySnippets.aylac-top.networkMap.ntfy.vHost}/network-status
14 '';
15in {
16 systemd.services.notify-on-unplug = {
17 description = "Sends a notification when the computer is unplugged from the charger.";
18 after = ["network.target"];
19 serviceConfig = {
20 Type = "oneshot";
21 ExecStart = pkgs.writeShellScript "notify-on-unplug" notifyOnUnplugScript;
22 };
23 };
24
25 services.udev.extraRules = ''
26 SUBSYSTEM=="power_supply", ATTR{online}=="0", TAG+="systemd", ENV{SYSTEMD_WANTS}="notify-on-unplug.service"
27 '';
28}