Don't ntfy for logrotate failures and add container names to ntfy alerts

This commit is contained in:
2026-03-13 20:00:09 -07:00
parent 4899a37a82
commit bd71d6e2f5
5 changed files with 20 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ with lib;
let let
cfg = config.pia-vpn; cfg = config.pia-vpn;
hostName = config.networking.hostName;
mkContainer = name: ctr: { mkContainer = name: ctr: {
autoStart = true; autoStart = true;
@@ -28,6 +29,9 @@ let
config = { config, pkgs, lib, ... }: { config = { config, pkgs, lib, ... }: {
imports = allModules ++ [ ctr.config ]; imports = allModules ++ [ ctr.config ];
ntfy-alerts.ignoredUnits = [ "logrotate" ];
ntfy-alerts.hostLabel = "${hostName}/${name}";
# Static IP with gateway pointing to VPN container # Static IP with gateway pointing to VPN container
networking.useNetworkd = true; networking.useNetworkd = true;
systemd.network.enable = true; systemd.network.enable = true;

View File

@@ -6,6 +6,7 @@ with lib;
let let
cfg = config.pia-vpn; cfg = config.pia-vpn;
hostName = config.networking.hostName;
scripts = import ./scripts.nix; scripts = import ./scripts.nix;
# Port forwarding derived state # Port forwarding derived state
@@ -98,6 +99,8 @@ in
# Route ntfy alerts through the host proxy (VPN container has no gateway on eth0) # Route ntfy alerts through the host proxy (VPN container has no gateway on eth0)
ntfy-alerts.curlExtraArgs = "--proxy http://${cfg.hostAddress}:${toString cfg.proxyPort}"; ntfy-alerts.curlExtraArgs = "--proxy http://${cfg.hostAddress}:${toString cfg.proxyPort}";
ntfy-alerts.ignoredUnits = [ "logrotate" ];
ntfy-alerts.hostLabel = "${hostName}/pia-vpn";
# Enable forwarding so bridge traffic can go through WG # Enable forwarding so bridge traffic can go through WG
boot.kernel.sysctl."net.ipv4.ip_forward" = 1; boot.kernel.sysctl."net.ipv4.ip_forward" = 1;

View File

@@ -26,6 +26,12 @@
default = [ ]; default = [ ];
description = "Unit names to skip failure notifications for."; description = "Unit names to skip failure notifications for.";
}; };
hostLabel = lib.mkOption {
type = lib.types.str;
default = config.networking.hostName;
description = "Label used in ntfy alert titles to identify this host/container.";
};
}; };
config = lib.mkIf config.thisMachine.hasRole."ntfy" { config = lib.mkIf config.thisMachine.hasRole."ntfy" {

View File

@@ -32,7 +32,7 @@ in
--max-time 30 --retry 3 \ --max-time 30 --retry 3 \
${cfg.curlExtraArgs} \ ${cfg.curlExtraArgs} \
-H "Authorization: Bearer $NTFY_TOKEN" \ -H "Authorization: Bearer $NTFY_TOKEN" \
-H "Title: Service failure on ${config.networking.hostName}" \ -H "Title: Service failure on ${cfg.hostLabel}" \
-H "Priority: high" \ -H "Priority: high" \
-H "Tags: rotating_light" \ -H "Tags: rotating_light" \
-H "Message: Unit $unit failed at $(date +%c)" \ -H "Message: Unit $unit failed at $(date +%c)" \

View File

@@ -1,4 +1,4 @@
{ config, lib, ... }: { config, lib, allModules, ... }:
# Gitea Actions Runner inside a NixOS container. # Gitea Actions Runner inside a NixOS container.
# The container shares the host's /nix/store (read-only) and nix-daemon socket, # The container shares the host's /nix/store (read-only) and nix-daemon socket,
@@ -9,6 +9,7 @@
let let
thisMachineIsARunner = config.thisMachine.hasRole."gitea-actions-runner"; thisMachineIsARunner = config.thisMachine.hasRole."gitea-actions-runner";
hostOverlays = config.nixpkgs.overlays; hostOverlays = config.nixpkgs.overlays;
hostName = config.networking.hostName;
containerName = "gitea-runner"; containerName = "gitea-runner";
giteaRunnerUid = 991; giteaRunnerUid = 991;
giteaRunnerGid = 989; giteaRunnerGid = 989;
@@ -32,9 +33,12 @@ in
}; };
config = { config, lib, pkgs, ... }: { config = { config, lib, pkgs, ... }: {
system.stateVersion = "25.11"; imports = allModules;
nixpkgs.overlays = hostOverlays; nixpkgs.overlays = hostOverlays;
ntfy-alerts.ignoredUnits = [ "logrotate" ];
ntfy-alerts.hostLabel = "${hostName}/${containerName}";
services.gitea-actions-runner.instances.inst = { services.gitea-actions-runner.instances.inst = {
enable = true; enable = true;
name = containerName; name = containerName;