summaryrefslogtreecommitdiff
path: root/hosts/hp-envy-office/ups.nix
blob: 8af0bcd8b89344750631c0fd487d13c09c7221bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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;
		};
	};
}