2024-04-20 00:40:44 +02:00
|
|
|
{ pkgs, config, ... }:
|
2024-04-19 21:10:14 +02:00
|
|
|
{
|
|
|
|
power.ups = {
|
|
|
|
enable = true;
|
|
|
|
ups."eaton" = {
|
|
|
|
driver = "usbhid-ups";
|
|
|
|
port = "auto";
|
|
|
|
};
|
|
|
|
upsmon.enable = false;
|
2024-04-20 00:20:22 +02:00
|
|
|
users."eatonMon" = {
|
2024-04-20 00:40:44 +02:00
|
|
|
passwordFile = config.age.secrets."eatonmon-password_file".path;
|
2024-04-20 00:20:22 +02:00
|
|
|
upsmon = "primary";
|
|
|
|
};
|
|
|
|
upsmon.monitor."eaton" = {
|
|
|
|
user = "eatonMon";
|
|
|
|
};
|
|
|
|
schedulerRules =
|
|
|
|
let
|
|
|
|
cmdScript = pkgs.writeShellApplication {
|
|
|
|
name = "upssched-cmd.sh";
|
|
|
|
runtimeInputs = with pkgs; [ systemd ];
|
|
|
|
text = ''
|
|
|
|
case $1 in
|
|
|
|
shutdown) shutdown now
|
|
|
|
# TODO : warn
|
|
|
|
# TODO : warn & log on unknown cmd
|
|
|
|
esac
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
rules = ''
|
|
|
|
CMDSCRIPT ${cmdScript}/bin/upssched-cmd.sh
|
|
|
|
PIPEFN /var/state/ups/upssched/upssched.pipe
|
|
|
|
LOCKFN /var/state/ups/upssched/upssched.lock
|
|
|
|
AT LOWBATT * EXECUTE shutdown
|
|
|
|
AT ONBATT * START-TIMER shutdown 900
|
|
|
|
AT ONLINE * CANCEL-TIMER shutdown
|
|
|
|
# TODO : warn admins at COMMBAD NOCOMM BYPASS (and maybe at ONBATT)
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
(pkgs.writeTextFile {
|
|
|
|
name = "upssched.conf";
|
|
|
|
text = rules;
|
|
|
|
}).outPath;
|
2024-04-19 21:10:14 +02:00
|
|
|
};
|
2024-04-20 00:20:22 +02:00
|
|
|
|
|
|
|
systemd.tmpfiles.settings."10-upsmon" =
|
|
|
|
let
|
|
|
|
root = {
|
|
|
|
user = "root";
|
|
|
|
group = "root";
|
|
|
|
mode = "0600";
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
"/var/state/ups/upssched".d = root // {
|
|
|
|
mode = "0700";
|
|
|
|
};
|
|
|
|
"/var/state/ups/upssched/upssched.pipe".p = root;
|
|
|
|
};
|
|
|
|
|
2024-04-19 23:30:26 +02:00
|
|
|
services.prometheus.exporters.nut = {
|
|
|
|
enable = true;
|
|
|
|
listenAddress = "100.80.255.180";
|
|
|
|
port = 9199;
|
|
|
|
};
|
2024-04-19 21:10:14 +02:00
|
|
|
}
|