refactor(systemd-notify): take it from nix-modules
This commit is contained in:
parent
e1699ba735
commit
c1afcb7768
2 changed files with 50 additions and 1 deletions
|
@ -39,6 +39,7 @@
|
|||
"extranix"
|
||||
"openbao"
|
||||
"forgejo-multiuser-nix-runners"
|
||||
"systemd-notify"
|
||||
])
|
||||
++ [
|
||||
"${sources.agenix}/modules/age.nix"
|
||||
|
@ -52,7 +53,6 @@
|
|||
"services/forgejo-nix-runners"
|
||||
"services/nginx-sni"
|
||||
"services/reaction"
|
||||
"services/systemd-notify"
|
||||
"services/victorialogs"
|
||||
"services/victoriametrics"
|
||||
]
|
||||
|
|
49
modules/nixos/systemd-notify.nix
Normal file
49
modules/nixos/systemd-notify.nix
Normal file
|
@ -0,0 +1,49 @@
|
|||
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
|
||||
#
|
||||
# SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
{ config, lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib)
|
||||
mkEnableOption
|
||||
mkIf
|
||||
mkOption
|
||||
mkForce
|
||||
optional
|
||||
;
|
||||
inherit (lib.types) attrsOf str submodule;
|
||||
|
||||
cfg = config.services.systemd-notify;
|
||||
in
|
||||
|
||||
{
|
||||
options.services.systemd-notify = {
|
||||
enable = mkEnableOption "notifications when a systemd unit fails.";
|
||||
|
||||
command = mkOption {
|
||||
type = str;
|
||||
description = ''
|
||||
Command to run on failure of a systemd unit.
|
||||
Takes the name of the failed unit as an argument.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
options.systemd.services = mkOption {
|
||||
type = attrsOf (submodule {
|
||||
config.onFailure = optional cfg.enable "email@%n.service";
|
||||
});
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
systemd.services."email@" = {
|
||||
description = "Sends a status mail via sendmail on service failures.";
|
||||
onFailure = mkForce [ ]; # Avoid recursive failures
|
||||
serviceConfig = {
|
||||
ExecStart = "${cfg.command} %i";
|
||||
Type = "oneshot";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue