summaryrefslogtreecommitdiff
path: root/modules/nixos
diff options
context:
space:
mode:
Diffstat (limited to 'modules/nixos')
-rw-r--r--modules/nixos/personal/monitoring.nix62
1 files changed, 30 insertions, 32 deletions
diff --git a/modules/nixos/personal/monitoring.nix b/modules/nixos/personal/monitoring.nix
index 44eceb6..6e83a09 100644
--- a/modules/nixos/personal/monitoring.nix
+++ b/modules/nixos/personal/monitoring.nix
@@ -1,11 +1,20 @@
-{ config, lib, pkgs, ... }:
-
{
+ config,
+ lib,
+ pkgs,
+ ...
+}: {
options.systemd.services = lib.mkOption {
type = with lib.types;
- attrsOf (submodule ({ name, ... }: {
- personal.monitor =
- lib.mkEnableOption "e-mail monitoring for the ${name} service";
+ attrsOf (submodule ({
+ name,
+ config,
+ lib,
+ ...
+ }: {
+ options.personal.monitor =
+ lib.mkEnableOption "e-mail monitoring for the ${name} seervice";
+ config.onFailure = lib.optional config.personal.monitor "notify@%i.service";
}));
};
@@ -24,33 +33,22 @@
};
};
- 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:
+ systemd.services."notify@" = lib.mkDefault {
+ description = "Send the status of the %i service as an e-mail.";
+ serviceConfig.type = "oneshot";
+ scriptArgs = "%i";
+ script = let
+ netCfg = config.networking;
+ me = "${builtins.toString netCfg.hostName}.${builtins.toString netCfg.domain}";
+ in ''
+ 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";
- };
- };
- }
- (builtins.mapAttrs (_: value: {
- onFailure = lib.optional value.personal.monitor "notify@%i.service";
- }) config.systemd.services)
- ];
+ $(systemctl status $service)
+ " | ${pkgs.msmtp}/bin/msmtp quentin@aristote.fr
+ '';
+ };
};
}