Code change:
}; }; <ins> listenOptions = { options = { address = mkOption { type = types.str; description = lib.mdDoc '' Address of the interface for `upsd` to listen on. See `man upsd.conf` for details. ''; }; port = mkOption { type = types.port; default = defaultPort; description = lib.mdDoc '' TCP port for `upsd` to listen on. See `man upsd.conf` for details. ''; }; }; }; upsdOptions = { options = { enable = mkOption { type = types.bool; defaultText = literalMD "`true` if `mode` is one of `standalone`, `netserver`"; description = mdDoc "Whether to enable `upsd`."; }; listen = mkOption { type = with types; listOf (submodule listenOptions); default = []; example = [ { address = "192.168.50.1"; } { address = "::1"; port = 5923; } ]; description = lib.mdDoc '' Address of the interface for `upsd` to listen on. See `man upsd` for details`. ''; }; extraConfig = mkOption { type = types.lines; default = ""; description = lib.mdDoc '' Additional lines to add to `upsd.conf`. ''; }; }; config = { enable = mkDefault (elem cfg.mode [ "standalone" "netserver" ]); }; }; monitorOptions = { name, config, ... }: { options = { system = mkOption { type = types.str; default = name; description = lib.mdDoc '' Identifier of the UPS to monitor, in this form: `<upsname>[@<hostname>[:<port>]]` See `upsmon.conf` for details. ''; }; powerValue = mkOption { type = types.int; default = 1; description = lib.mdDoc '' Number of power supplies that the UPS feeds on this system. See `upsmon.conf` for details. ''; }; user = mkOption { type = types.str; description = lib.mdDoc '' Username from `upsd.users` for accessing this UPS. See `upsmon.conf` for details. ''; }; passwordFile = mkOption { type = types.str; defaultText = literalMD "power.ups.users.${user}.passwordFile"; description = lib.mdDoc '' The full path to a file containing the password from `upsd.users` for accessing this UPS. The password file is read on service start. See `upsmon.conf` for details. ''; }; type = mkOption { type = types.str; default = "master"; description = lib.mdDoc '' The relationship with `upsd`. See `upsmon.conf` for details. ''; }; }; config = { passwordFile = mkDefault cfg.users.${config.user}.passwordFile; }; }; upsmonOptions = { options = { enable = mkOption { type = types.bool; defaultText = literalMD "`true` if `mode` is one of `standalone`, `netserver`, `netclient`"; description = mdDoc "Whether to enable `upsmon`."; }; monitor = mkOption { type = with types; attrsOf (submodule monitorOptions); default = {}; description = lib.mdDoc '' Set of UPS to monitor. See `man upsmon.conf` for details. ''; }; settings = mkOption { type = nutFormat.type; default = {}; defaultText = literalMD '' { MINSUPPLIES = 1; RUN_AS_USER = "root"; NOTIFYCMD = "''${pkgs.nut}/bin/upssched"; SHUTDOWNCMD = "''${pkgs.systemd}/bin/shutdown now"; } ''; description = mdDoc "Additional settings to add to `upsmon.conf`."; example = literalMD '' { MINSUPPLIES = 2; NOTIFYFLAG = [ [ "ONLINE" "SYSLOG+EXEC" ] [ "ONBATT" "SYSLOG+EXEC" ] ]; } ''; }; }; config = { enable = mkDefault (elem cfg.mode [ "standalone" "netserver" "netclient" ]); settings = { RUN_AS_USER = "root"; # TODO: replace 'root' by another username. MINSUPPLIES = mkDefault 1; NOTIFYCMD = mkDefault "${pkgs.nut}/bin/upssched"; SHUTDOWNCMD = mkDefault "${pkgs.systemd}/bin/shutdown now"; MONITOR = flip mapAttrsToList cfg.upsmon.monitor (name: monitor: with monitor; [ system powerValue user ""@upsmon_password_${name}@"" type ]); }; }; }; userOptions = { options = { passwordFile = mkOption { type = types.str; description = lib.mdDoc '' The full path to a file that contains the user's (clear text) password. The password file is read on service start. ''; }; actions = mkOption { type = with types; listOf str; default = []; description = lib.mdDoc '' Allow the user to do certain things with upsd. See `man upsd.users` for details. ''; }; instcmds = mkOption { type = with types; listOf str; default = []; description = lib.mdDoc '' Let the user initiate specific instant commands. Use "ALL" to grant all commands automatically. For the full list of what your UPS supports, use "upscmd -l". See `man upsd.users` for details. ''; }; upsmon = mkOption { type = with types; nullOr str; default = null; description = lib.mdDoc '' Add the necessary actions for a upsmon process to work. See `man upsd.users` for details. ''; }; }; }; </ins> in

Related discussion:
text: flags , , may be needed instead of environment variables until a 2.7.5 release. Ref: Using for debug makes it non-forking, requiring a change to the systemd unit . I was able to get to run as non-root: 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.
Not stale; still relevant
Thanks 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 " = <percentage" and " = <seconds" 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 below. You must give it the path to your file. I just put a copy of it inside my /etc/nixos. Could probably add another variable to hold the path for convenience. `
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
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.
is my attempt at making generate the config files necessary for basic operation. If you are using , could you try out the changes and leave a review?