# SPDX-FileCopyrightText: 2024 Tom Hubrecht # # SPDX-License-Identifier: EUPL-1.2 { config, lib, ... }: let inherit (lib) getExe mapAttrs' mapAttrsToList mkOption mkForce nameValuePair ; inherit (lib.types) attrsOf package submodule; cfg = config.services.systemd-notify; in { options.services.systemd-notify = mkOption { type = attrsOf package; description = '' Commands to execute when a systemd unit fails. Attrs keys will be the unit name and attrs value is the command that will be run with the name of the failed unit as an argument. ''; default = { }; }; options.systemd.services = mkOption { type = attrsOf (submodule { config.onFailure = mapAttrsToList (name: _: "${name}@%n.service") cfg; }); }; config.systemd.services = mapAttrs' ( name: script: nameValuePair "${name}@" { description = "Run ${name} script on service failures."; onFailure = mkForce [ ]; # Avoid recursive failures serviceConfig = { ExecStart = "${getExe script} %i"; Type = "oneshot"; }; } ) cfg; }