Update UPS, NUT, network bridge, zfs backups, oh my

This commit is contained in:
Joseph Hanson 2024-04-02 07:11:09 -05:00
parent f81a81a675
commit 4d1eb8cd94
Signed by: jahanson
SSH key fingerprint: SHA256:vy6dKBECV522aPAwklFM3ReKAVB086rT3oWwiuiFG7o

View file

@ -3,7 +3,11 @@
# https://search.nixos.org/options and in the NixOS manual (`nixos-help`).
{ config, lib, pkgs, inputs, ... }:
let
upsPassword = "illgettoiteventually";
vendorid = "0764";
productid = "0501";
in
{
imports =
[
@ -31,10 +35,20 @@
# Network settings
networking = {
hostName = "gandalf"; # Define your hostname.
hostName = "gandalf";
hostId = "e2fc95cd";
useDHCP = false; # needed for bridge
networkmanager.enable = true;
firewall.enable = false;
interfaces = {
"enp130s0f0".useDHCP = true;
"enp130s0f1".useDHCP = true;
};
bridges = {
"br0" = {
interfaces = [ "enp130s0f1" ];
};
};
};
environment.systemPackages = with pkgs; [
@ -51,6 +65,94 @@
settings.PasswordAuthentication = false;
settings.KbdInteractiveAuthentication = false;
};
services.prometheus.exporters.zfs.enable = true;
services.prometheus.exporters.smartctl.enable = true;
# UPS & NUT
power.ups = {
enable = true;
ups.cyberpower = {
driver = "usbhid-ups";
port = "auto";
directives = [
"vendorid = ${vendorid}"
"productid = ${productid}"
"product = CP1500AVRLCDa"
"serial = CTHKY2013373"
"vendor = CPS"
"bus = 002"
];
};
};
users = {
users.nut = {
isSystemUser = true;
group = "nut";
# it does not seem to do anything with this directory
# but something errored without it, so whatever
home = "/var/lib/nut";
createHome = true;
};
groups.nut = { };
};
services.udev.extraRules = ''
SUBSYSTEM=="usb", ATTRS{idVendor}=="${vendorid}", ATTRS{idProduct}=="${productid}", MODE="664", GROUP="nut", OWNER="nut"
'';
systemd.services.upsd.serviceConfig = {
User = "root";
Group = "nut";
};
systemd.services.upsdrv.serviceConfig = {
User = "root";
Group = "nut";
};
# reference: https://github.com/networkupstools/nut/tree/master/conf
environment.etc = {
# all this file needs to do is exist
upsdConf = {
text = "";
target = "nut/upsd.conf";
mode = "0440";
group = "nut";
user = "nut";
};
upsdUsers = {
# update upsmonConf MONITOR to match
text = ''
[upsmon]
password = ${upsPassword}
upsmon master
'';
target = "nut/upsd.users";
mode = "0440";
group = "nut";
user = "nut";
};
# RUN_AS_USER is not a default
# the rest are from the sample
# grep -v '#' /nix/store/8nciysgqi7kmbibd8v31jrdk93qdan3a-nut-2.7.4/etc/upsmon.conf.sample
upsmonConf = {
text = ''
RUN_AS_USER nut
MINSUPPLIES 1
SHUTDOWNCMD "shutdown -h 0"
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY 5
MONITOR cyberpower@localhost 1 upsmon ${upsPassword} master
'';
target = "nut/upsmon.conf";
mode = "0444";
};
};
# NFS
services.nfs.server.enable = true;
@ -172,6 +274,46 @@
daily = 7;
monthly = 12;
};
"eru/hansonhive" = {
recursive = true;
autoprune = true;
autosnap = true;
hourly = 24;
daily = 7;
monthly = 12;
};
"eru/tm_joe" = {
recursive = true;
autoprune = true;
autosnap = true;
hourly = 24;
daily = 7;
monthly = 12;
};
"eru/tm_elisia" = {
recursive = true;
autoprune = true;
autosnap = true;
hourly = 24;
daily = 7;
monthly = 12;
};
"eru/containers/volumes/xo-data" = {
recursive = true;
autoprune = true;
autosnap = true;
hourly = 24;
daily = 7;
monthly = 12;
};
"eru/containers/volumes/xo-redis-data" = {
recursive = true;
autoprune = true;
autosnap = true;
hourly = 24;
daily = 7;
monthly = 12;
};
};
};
@ -195,4 +337,4 @@
# For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .
system.stateVersion = "23.11"; # Did you read the comment?
}
}