summaryrefslogtreecommitdiff
path: root/modules/nixos/personal/monitoring.nix
diff options
context:
space:
mode:
authorquentin@aristote.fr <quentin@aristote.fr>2023-08-09 20:43:52 +0200
committerquentin@aristote.fr <quentin@aristote.fr>2023-08-09 20:53:20 +0200
commitafcad6222a1e8bd6427e0ed1100bbd268de16475 (patch)
tree736ea1eb22632e6561b78759d907e7b3a2608f7d /modules/nixos/personal/monitoring.nix
parent861659c200c06984cf4b5dd924f362461c045593 (diff)
systemd: monitor: refactor options
Diffstat (limited to 'modules/nixos/personal/monitoring.nix')
-rw-r--r--modules/nixos/personal/monitoring.nix67
1 files changed, 34 insertions, 33 deletions
diff --git a/modules/nixos/personal/monitoring.nix b/modules/nixos/personal/monitoring.nix
index 8d72c3c..44eceb6 100644
--- a/modules/nixos/personal/monitoring.nix
+++ b/modules/nixos/personal/monitoring.nix
@@ -1,19 +1,17 @@
{ config, lib, pkgs, ... }:
-let cfg = config.personal.monitoring;
-in {
- options.personal.monitoring = {
- enable = lib.mkEnableOption "e-mail monitoring";
- services = lib.mkOption {
- type = with lib.types; listOf str;
- default = [ ];
- description = "The list of services whose failure should be notified.";
- };
+{
+ options.systemd.services = lib.mkOption {
+ type = with lib.types;
+ attrsOf (submodule ({ name, ... }: {
+ personal.monitor =
+ lib.mkEnableOption "e-mail monitoring for the ${name} service";
+ }));
};
config = {
programs.msmtp = {
- enable = cfg.enable;
+ enable = true;
accounts.default = {
auth = true;
tls = true;
@@ -26,30 +24,33 @@ in {
};
};
- systemd.services = lib.mkIf cfg.enable (lib.mkMerge ([{
- "notify@" = {
- enable = true;
- description = "Send the status of the %i service as an e-mail.";
- serviceConfig = {
- Type = "oneshot";
- ExecStart = let
- netCfg = config.networking;
- me = "${netCfg.hostName}.${netCfg.domain}";
- script = pkgs.writeScript "notify" ''
- #!${pkgs.runtimeShell}
- service="$1"
- echo \
- "Subject: ${me}: service $service failed
- Service $service failed on ${me}, with the following status:
+ systemd.services = lib.mkMerge [
+ config.systemd.services
+ {
+ "notify@" = lib.mkDefault {
+ description = "Send the status of the %i service as an e-mail.";
+ serviceConfig = {
+ Type = "oneshot";
+ ExecStart = let
+ netCfg = config.networking;
+ me = "${netCfg.hostName}.${netCfg.domain}";
+ script = pkgs.writeScript "notify" ''
+ #!${pkgs.runtimeShell}
+ service="$1"
+ echo \
+ "Subject: ${me}: service $service failed
+ Service $service failed on ${me}, with the following status:
- $(systemctl status $service)
- " | ${pkgs.msmtp}/bin/msmtp quentin@aristote.fr
- '';
- in "${script} %i";
+ $(systemctl status $service)
+ " | ${pkgs.msmtp}/bin/msmtp quentin@aristote.fr
+ '';
+ in "${script} %i";
+ };
};
- };
- }] ++ builtins.map
- (service: { "${service}".onFailure = [ "notify@%i.service" ]; })
- cfg.services));
+ }
+ (builtins.mapAttrs (_: value: {
+ onFailure = lib.optional value.personal.monitor "notify@%i.service";
+ }) config.systemd.services)
+ ];
};
}