#
# Uninterruptable power supply configuration.
#
# vim: et:ts=2:sw=2:
#
{ pkgs, ... }:
let
  upspass = "upsaccess";
in
{
  # Create a user to run the UPS daemon.
  services.openssh.settings.DenyUsers = [ "ups" ];
  users.users.ups = {
    isSystemUser = true;
    password = upspass;
    group = "ups";
    shell = "/bin/false";
  };
  users.groups.ups = { };

  power.ups = {
    enable = true;
    upsd.enable = true;

    users.deprekated = {
      instcmds = [ "all" ];
      actions = [
        "set"
        "fsd"
      ];
      upsmon = "primary";
      passwordFile = "${pkgs.writeText "password" upspass}";
    };

    # Serve a single UPS.
    ups.lix = {
      description = "UPS guarding the TMLLC build server and the Lix build cluster.";

      driver = "usbhid-ups";
      port = "auto";
      directives = [
        "vendorid = '051D'"
        "productid = '0002'"
        "product = 'Back-UPS NS 1500M2 FW:957.e5 .D USB FW:e5'"
        "serial = '5B2333T55573'"
        "vendor = 'American Power Conversion'"
        "bus = '009'"
      ];
    };

    upsmon = {
      enable = true;
      monitor.lix = {
        powerValue = 1;
        user = "deprekated";
      };
    };

  };
}
