modules: add services/apcupsd
This commit is contained in:
parent
7c7c31da67
commit
10d4e245f8
1 changed files with 47 additions and 0 deletions
47
modules/modules/services/apcupsd.nix
Normal file
47
modules/modules/services/apcupsd.nix
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
{ config, options, lib, pkgs, ... }:
|
||||||
|
with lib;
|
||||||
|
with lib.hlissner;
|
||||||
|
let
|
||||||
|
cfg = config.modules.services.apcupsd;
|
||||||
|
port = 3551;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.modules.services.apcupsd = with types; {
|
||||||
|
enable = mkBoolOpt false;
|
||||||
|
primary = mkBoolOpt true;
|
||||||
|
config = {
|
||||||
|
address = mkOpt str "127.0.0.1";
|
||||||
|
hooks = mkOpt (attrsOf lines) { };
|
||||||
|
battery_level = mkOpt int (if cfg.primary then 35 else 50);
|
||||||
|
minutes = mkOpt int (if cfg.primary then 5 else 10);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
services.apcupsd = {
|
||||||
|
enable = true;
|
||||||
|
configText = ''
|
||||||
|
UPSNAME UPS
|
||||||
|
UPSCLASS standalone
|
||||||
|
UPSMODE disable
|
||||||
|
NETSERVER on
|
||||||
|
NISPORT ${toString port}
|
||||||
|
|
||||||
|
BATTERYLEVEL ${toString cfg.config.battery_level}
|
||||||
|
MINUTES ${toString cfg.config.minutes}
|
||||||
|
'' +
|
||||||
|
(if cfg.primary then ''
|
||||||
|
UPSTYPE usb
|
||||||
|
UPSCABLE usb
|
||||||
|
NISIP ${cfg.config.address}
|
||||||
|
'' else ''
|
||||||
|
UPSCABLE ether
|
||||||
|
UPSTYPE net
|
||||||
|
DEVICE ${cfg.config.address}:${toString port}
|
||||||
|
POLLTIME 10
|
||||||
|
'');
|
||||||
|
hooks = cfg.config.hooks;
|
||||||
|
};
|
||||||
|
networking.firewall.allowedTCPPorts = mkIf cfg.primary [ port ];
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue