-
-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NixOS power.ups module does not generate all needed config files #91681
Comments
OK, should've read the whole module: I'm supposed to supply the missing /etc/nut files myself because it's unwise to keep them in the store (they could contain passwords and whatnot, I guess?). Declaring (in the service definitions) the state directory to be |
Also (sorry for the semi-off-topic) what are best practices for referencing hand-written config files without their contents winding up in the store? Double-symlinking? If this is documented somewhere, then I haven't found where. |
I was struggling with the same problem as @cmm until I noticed this bug report. After copying and editing I think this should be more discoverable. If it's not appropriate to copy those sample files to
|
I marked this as stale due to inactivity. → More info |
Agreed this should be more discoverable. Perhaps at least In case it helps anyone, I got it working with something like this:
|
I was hit this bug today, too. Maybe we can fix it by using a startup unit that handles the secrets and setup the state directories like nextcloud or syncthing do |
Been working on First, Using I was able to get
I'm still working on understanding how to manage state directories in NixOS but this was needed:
|
I set out to get my UPS (cyberpower CP1500 AVR UPS) working with NixOS today. This was the first issue I came across, I figured this was the best place to share my configuration. I probably made this more complex than it needed to be because I have no idea what I am doing, and it is definitely not secure; one problem at a time. let
vid = "0764";
pid = "0501";
password = "TODO";
in
{
# at some point something will make a /var/state/ups directory,
# chown that to nut:
# $ sudo chown nut:nut /var/state/ups
power.ups = {
enable = true;
mode = "standalone";
# debug by calling the driver:
# $ sudo NUT_CONFPATH=/etc/nut/ usbhid-ups -u nut -D -a cyberpower
ups.cyberpower = {
# find your driver here:
# https://networkupstools.org/docs/man/usbhid-ups.html
driver = "usbhid-ups";
description = "CP1500 AVR UPS";
port = "auto";
directives = [
"vendorid = ${vid}"
"productid = ${pid}"
];
# this option is not valid for usbhid-ups
maxStartDelay = null;
};
maxStartDelay = 10;
};
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}=="${vid}", ATTRS{idProduct}=="${pid}", MODE="664", GROUP="nut", OWNER="nut"
'';
systemd.services.upsd.serviceConfig = {
User = "nut";
Group = "nut";
};
systemd.services.upsdrv.serviceConfig = {
User = "nut";
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 = ${password}
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 ${password} master
'';
target = "nut/upsmon.conf";
mode = "0444";
};
};
} |
Not stale; still relevant |
Thanks @newAM for providing your standalone config! I learned a ton tweaking it into a netserver config! The below config creates a working NUT netserver that other machines on your local network can be connected to. The only thing I have yet to figure out is a secure way to include passwords in .nix files that won't show up if I push my local copy to github. Any ideas? If you want to tweak when NUT shuts down your computers you can modify the values of "override.battery.charge.low = " and "override.battery.runtime.low = " under "directives". SHUTDOWNCMD will be triggered when both conditions are met. The "ignorelb" directive is necessary to have NUT ignore the UPS's defaults. Anyone using this config may want to make sure SHUTDOWNCMD and NOTIFYCMD point to the correct binaries in their filesystem. One other thing of note is to check the value of the "schedulerRules" field under power.ups below. You must give it the path to your upssched.conf file. I just put a copy of it inside my /etc/nixos. Could probably add another variable to hold the path for convenience.
|
@justinmakes For secrets in nix config, I think the current recommendation is to put it in a separate file and not include it in the repo. See also #24288 |
I have been using sops-nix to commit encrypted passwords to my NixOS repo, but I have yet to put in the elbow grease to make this work with my upsmon password. |
#213006 is my attempt at making |
Describe the bug
The following
configuration.nix
snippet:results in services failing to start due to missing config files etc.
upsmon
:Can't open /etc/nut//upsmon.conf: No such file or directory
upsd
:stat /etc/nut//upsd.conf: No such file or directory
(
upsdrv
fails too, but that could be down to the fact that I haven't plugged the UPS in yet -- but for the record, it complainsCan't chdir to /var/lib/nut/: No such file or directory
)Expected behavior
I'd expect the services to start successfully (and probably complain about the missing actual UPS).
Notify maintainers
(The UPS module appears to have received only drive-by changes for the last several years, so no idea who to bug personally).
Metadata
"x86_64-linux"
Linux 5.4.48, NixOS, 20.03.2351.f8248ab6d9e (Markhor)
yes
yes
nix-env (Nix) 2.3.6
"nixos-20.03.2351.f8248ab6d9e"
/nix/var/nix/profiles/per-user/root/channels/nixos
Maintainer information:
The text was updated successfully, but these errors were encountered: