# SPDX-FileCopyrightText: 2024 Lubin Bailly # # SPDX-License-Identifier: EUPL-1.2 { config, lib, pkgs, meta, name, ... }: { power.ups = { enable = true; ups.eaton = { driver = "usbhid-ups"; port = "auto"; }; users.eatonmon = { passwordFile = config.age.secrets."eatonmon-password_file".path; upsmon = "primary"; }; upsmon.monitor.eaton = { user = "eatonmon"; }; schedulerRules = let cmdScript = pkgs.writeShellApplication { name = "upssched-cmd.sh"; runtimeInputs = with pkgs; [ systemd msmtp ]; text = '' case $1 in shutdown-low) MEANING="Battery is low, shutting down.";; shutdown-batt) MEANING="On battery for 15min, shutting down.";; warn-batt) MEANING="Power line faillure, going on battery.";; warn-comm) MEANING="Communication with the UPS was broken.";; warn-bypass) MEANING="The UPS is not protecting the server, power line failure would kill $HOSTNAME instantly.";; *) MEANING="Signal unknown, check configuration.";; esac sendmail -i -t <