about summary refs log tree commit diff
path: root/nixos/modules/services/monitoring
diff options
context:
space:
mode:
authorMajiir Paktu <majiir@nabaal.net>2023-01-22 13:27:02 -0500
committerMajiir Paktu <majiir@nabaal.net>2023-12-02 22:42:14 -0500
commit09002e9d23eaa33f7cbcd2107e1a9a334154ef3e (patch)
treee3524b194c15d35f7f813acf2fb7494e14c7acf4 /nixos/modules/services/monitoring
parent6998cf86e9a6ef83b32956337f65aba8656671fe (diff)
downloadnixlib-09002e9d23eaa33f7cbcd2107e1a9a334154ef3e.tar
nixlib-09002e9d23eaa33f7cbcd2107e1a9a334154ef3e.tar.gz
nixlib-09002e9d23eaa33f7cbcd2107e1a9a334154ef3e.tar.bz2
nixlib-09002e9d23eaa33f7cbcd2107e1a9a334154ef3e.tar.lz
nixlib-09002e9d23eaa33f7cbcd2107e1a9a334154ef3e.tar.xz
nixlib-09002e9d23eaa33f7cbcd2107e1a9a334154ef3e.tar.zst
nixlib-09002e9d23eaa33f7cbcd2107e1a9a334154ef3e.zip
nixos/ups: various fixes & clean up
- Ensure NUT_STATEPATH exists (fixes service startup)
- Use mode option to enable services (fixes #113735)
- Remove extraneous slash in paths (fixes confusing logs)
- Support reload for upsmon and upsd
- Remove ExecStart wrapper scripts
Diffstat (limited to 'nixos/modules/services/monitoring')
-rw-r--r--nixos/modules/services/monitoring/ups.nix56
1 files changed, 29 insertions, 27 deletions
diff --git a/nixos/modules/services/monitoring/ups.nix b/nixos/modules/services/monitoring/ups.nix
index efef2d777acd..4777da327b85 100644
--- a/nixos/modules/services/monitoring/ups.nix
+++ b/nixos/modules/services/monitoring/ups.nix
@@ -6,9 +6,7 @@ with lib;
 
 let
   cfg = config.power.ups;
-in
 
-let
   upsOptions = {name, config, ...}:
   {
     options = {
@@ -103,19 +101,14 @@ in
     # powerManagement.powerDownCommands
 
     power.ups = {
-      enable = mkOption {
-        default = false;
-        type = with types; bool;
-        description = lib.mdDoc ''
-          Enables support for Power Devices, such as Uninterruptible Power
-          Supplies, Power Distribution Units and Solar Controllers.
-        '';
-      };
+      enable = mkEnableOption (lib.mdDoc ''
+        Enables support for Power Devices, such as Uninterruptible Power
+        Supplies, Power Distribution Units and Solar Controllers.
+      '');
 
-      # This option is not used yet.
       mode = mkOption {
         default = "standalone";
-        type = types.str;
+        type = types.enum [ "none" "standalone" "netserver" "netclient" ];
         description = lib.mdDoc ''
           The MODE determines which part of the NUT is to be started, and
           which configuration files must be modified.
@@ -180,38 +173,48 @@ in
     environment.systemPackages = [ pkgs.nut ];
 
     systemd.services.upsmon = {
+      enable = mkDefault (elem cfg.mode [ "standalone" "netserver" "netclient" ]);
       description = "Uninterruptible Power Supplies (Monitor)";
       after = [ "network.target" ];
       wantedBy = [ "multi-user.target" ];
-      serviceConfig.Type = "forking";
-      script = "${pkgs.nut}/sbin/upsmon";
-      environment.NUT_CONFPATH = "/etc/nut/";
-      environment.NUT_STATEPATH = "/var/lib/nut/";
+      serviceConfig = {
+        Type = "forking";
+        ExecStart = "${pkgs.nut}/sbin/upsmon";
+        ExecReload = "${pkgs.nut}/sbin/upsmon -c reload";
+      };
+      environment.NUT_CONFPATH = "/etc/nut";
+      environment.NUT_STATEPATH = "/var/lib/nut";
     };
 
     systemd.services.upsd = {
+      enable = mkDefault (elem cfg.mode [ "standalone" "netserver" ]);
       description = "Uninterruptible Power Supplies (Daemon)";
       after = [ "network.target" "upsmon.service" ];
       wantedBy = [ "multi-user.target" ];
       serviceConfig.Type = "forking";
-      # TODO: replace 'root' by another username.
-      script = "${pkgs.nut}/sbin/upsd -u root";
-      environment.NUT_CONFPATH = "/etc/nut/";
-      environment.NUT_STATEPATH = "/var/lib/nut/";
+      serviceConfig = {
+        Type = "forking";
+        # TODO: replace 'root' by another username.
+        ExecStart = "${pkgs.nut}/sbin/upsd -u root";
+        ExecReload = "${pkgs.nut}/sbin/upsd -c reload";
+      };
+      environment.NUT_CONFPATH = "/etc/nut";
+      environment.NUT_STATEPATH = "/var/lib/nut";
     };
 
     systemd.services.upsdrv = {
+      enable = mkDefault (elem cfg.mode [ "standalone" "netserver" ]);
       description = "Uninterruptible Power Supplies (Register all UPS)";
       after = [ "upsd.service" ];
       wantedBy = [ "multi-user.target" ];
-      # TODO: replace 'root' by another username.
-      script = "${pkgs.nut}/bin/upsdrvctl -u root start";
       serviceConfig = {
         Type = "oneshot";
         RemainAfterExit = true;
+        # TODO: replace 'root' by another username.
+        ExecStart = "${pkgs.nut}/bin/upsdrvctl -u root start";
       };
-      environment.NUT_CONFPATH = "/etc/nut/";
-      environment.NUT_STATEPATH = "/var/lib/nut/";
+      environment.NUT_CONFPATH = "/etc/nut";
+      environment.NUT_STATEPATH = "/var/lib/nut";
     };
 
     environment.etc = {
@@ -223,9 +226,7 @@ in
         ''
           maxstartdelay = ${toString cfg.maxStartDelay}
 
-          ${flip concatStringsSep (forEach (attrValues cfg.ups) (ups: ups.summary)) "
-
-          "}
+          ${concatStringsSep "\n\n" (forEach (attrValues cfg.ups) (ups: ups.summary))}
         '';
       "nut/upssched.conf".source = cfg.schedulerRules;
       # These file are containing private information and thus should not
@@ -241,6 +242,7 @@ in
 
     systemd.tmpfiles.rules = [
       "d /var/state/ups -"
+      "d /var/lib/nut 700"
     ];