{ config, ... }:
let
  enableUps = true;
  upsName = "nas-ups";
  upsUser = "nas-admin";
in
{
  power.ups = {
    enable = enableUps;
    openFirewall = enableUps;
    mode = "netserver";

    ups = {
      "${upsName}" = {
        description = "NAS UPS";
        driver = "usbhid-ups";
        port = "auto";
      };
    };

    users."${upsUser}" = {
      passwordFile = config.sops.secrets."jallen-nas/ups_password".path;
      actions = [ "ALL" ];
      instcmds = [ "ALL" ];
      upsmon = "primary";
    };

    upsmon = {
      enable = enableUps;
      monitor."${upsName}" = {
        passwordFile = config.sops.secrets."jallen-nas/ups_password".path;
        user = upsUser;
      };
    };

    upsd = {
      enable = enableUps;
      listen = [
        {
          address = "0.0.0.0";
          port = 3493;
        }
      ];
    };
  };

  services = {
    apcupsd = {
      enable = true;
    };
  };
}
