From e918c6ccbcfe19c73cffbdecac2e2ea10479e7e0 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Thu, 21 May 2026 22:55:23 -0500 Subject: office ups experimental setup --- hosts/hp-envy-office/ups.nix | 85 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 hosts/hp-envy-office/ups.nix diff --git a/hosts/hp-envy-office/ups.nix b/hosts/hp-envy-office/ups.nix new file mode 100644 index 0000000..8af0bcd --- /dev/null +++ b/hosts/hp-envy-office/ups.nix @@ -0,0 +1,85 @@ +let + passwordFile = builtins.toFile "password" "password"; +in { + power.ups = { + enable = true; + ups."UPS-1" = { + driver = "usbhid-ups"; + port = "auto"; + directives = [ + "offdelay = 360" + "ondelay = 370" + "lowbatt = 40" + "ignorelb" + ]; + }; + upsd = { + listen = [ + { + address = "127.0.0.1"; + port = 3493; + } + { + address = "::1"; + port = 3493; + } + ]; + }; + users."nut-admin" = { + # A file that contains just the password. + inherit passwordFile; + upsmon = "primary"; + }; + upsmon.monitor."UPS-1" = { + inherit passwordFile; + system = "UPS-1@localhost"; + powerValue = 1; + user = "nut-admin"; + type = "primary"; + }; + upsmon.settings = { + # This configuration file declares how upsmon is to handle + # NOTIFY events. + + # POWERDOWNFLAG and SHUTDOWNCMD is provided by NixOS default + # values + + # values provided by ConfigExamples 3.0 book + NOTIFYMSG = [ + [ "ONLINE" ''"UPS %s: On line power."'' ] + [ "ONBATT" ''"UPS %s: On battery."'' ] + [ "LOWBATT" ''"UPS %s: Battery is low."'' ] + [ "REPLBATT" ''"UPS %s: Battery needs to be replaced."'' ] + [ "FSD" ''"UPS %s: Forced shutdown in progress."'' ] + [ "SHUTDOWN" ''"Auto logout and shutdown proceeding."'' ] + [ "COMMOK" ''"UPS %s: Communications (re-)established."'' ] + [ "COMMBAD" ''"UPS %s: Communications lost."'' ] + [ "NOCOMM" ''"UPS %s: Not available."'' ] + [ "NOPARENT" ''"upsmon parent dead, shutdown impossible."'' ] + ]; + NOTIFYFLAG = [ + [ "ONLINE" "SYSLOG+WALL" ] + [ "ONBATT" "SYSLOG+WALL" ] + [ "LOWBATT" "SYSLOG+WALL" ] + [ "REPLBATT" "SYSLOG+WALL" ] + [ "FSD" "SYSLOG+WALL" ] + [ "SHUTDOWN" "SYSLOG+WALL" ] + [ "COMMOK" "SYSLOG+WALL" ] + [ "COMMBAD" "SYSLOG+WALL" ] + [ "NOCOMM" "SYSLOG+WALL" ] + [ "NOPARENT" "SYSLOG+WALL" ] + ]; + # every RBWARNTIME seconds, upsmon will generate a replace + # battery NOTIFY event + RBWARNTIME = 216000; + # every NOCOMMWARNTIME seconds, upsmon will generate a UPS + # unreachable NOTIFY event + NOCOMMWARNTIME = 300; + # after sending SHUTDOWN NOTIFY event to warn users, upsmon + # waits FINALDELAY seconds long before executing SHUTDOWNCMD + # Some UPS's don't give much warning for low battery and will + # require a value of 0 here for aq safe shutdown. + FINALDELAY = 0; + }; + }; +} -- cgit v1.2.3