Code change:
let cfg = config.power.ups; <del> in </del> <ins> defaultPort = 3493; nutFormat = { type = with lib.types; let singleAtom = nullOr (oneOf [ bool int float str ]) // { description = "atom (null, bool, int, float or string)"; }; in attrsOf (oneOf [ singleAtom (listOf (nonEmptyListOf singleAtom)) ]); generate = name: value: let normalizedValue = lib.mapAttrs (key: val: if lib.isList val then forEach val (elem: if lib.isList elem then elem else [elem]) else if val == null then [] else [[val]] ) value; mkValueString = concatMapStringsSep " " (v: let str = generators.mkValueStringDefault {} v; in # Quote the value if it has spaces and isn't already quoted. if (hasInfix " " str) && !(hasPrefix """ str && hasSuffix """ str) then ""${str}"" else str ); in pkgs.writeText name (lib.generators.toKeyValue { mkKeyValue = generators.mkKeyValueDefault { inherit mkValueString; } " "; listsAsDuplicateKeys = true; } normalizedValue); }; installSecrets = source: target: secrets: pkgs.writeShellScript "installSecrets.sh" '' install -m0600 -D ${source} "${target}" ${concatLines (forEach secrets (name: '' ${pkgs.replace-secret}/bin/replace-secret  '@${name}@'  "$CREDENTIALS_DIRECTORY/${name}"  "${target}" ''))} chmod u-w "${target}" ''; upsmonConf = nutFormat.generate "upsmon.conf" cfg.upsmon.settings; upsdUsers = pkgs.writeText "upsd.users" (let # This looks like INI, but it's not quite because the # 'upsmon' option lacks a '='. See: man upsd.users userConfig = name: user: concatStringsSep "n      " (concatLists [ [ "[${name}]" "password = "@upsdusers_password_${name}@"" ] (optional (user.upsmon != null) "upsmon ${user.upsmon}") (forEach user.actions (action: "actions = ${action}")) (forEach user.instcmds (instcmd: "instcmds = ${instcmd}")) ]); in concatStringsSep "nn" (mapAttrsToList userConfig cfg.users)); </ins> <del> let </del> upsOptions = {name, config, ...}: { options = {

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?