nixfiles/nixos/common/login-notify.nix
Kat Inskip 8a0fa4d5d1
Some checks failed
nodes / nodes check (push) Has been cancelled
nodes / nodes-home-home-base (push) Has been cancelled
nodes / nodes-home-home-graphical (push) Has been cancelled
nodes / nodes-home-home-neovim (push) Has been cancelled
nodes / nodes-home-home-shell (push) Has been cancelled
nodes / nodes-nixos-mai (push) Has been cancelled
nodes / nodes-nixos-mei (push) Has been cancelled
feat: ntfy...? :3
2025-10-13 12:58:51 -07:00

30 lines
780 B
Nix

{
pkgs,
lib,
config,
...
}: let
inherit (lib.modules) mkAfter mkDefault;
in {
sops.secrets.ssh-notify = {
sopsFile = ./secrets.yaml;
};
security.pam.services.sshd.text = let
notify = pkgs.writeShellScript "notify" ''
set -o allexport
source ${config.sops.secrets.ssh-notify.path}
set +o allexport
if [ "''${PAM_TYPE}" = "open_session" ]; then
curl -s -X POST \
-H "Authorization: Bearer ''${SSH_NOTIFY_TOKEN}" \
-H prio:high \
-H tags:warning \
-d "SSH login to ${config.networking.hostName}: ''${PAM_USER} from ''${PAM_RHOST}" \
https://ntfy.kittywit.ch/alerts
fi
'';
in
mkDefault (mkAfter ''
session optional pam_exec.so seteuid ${notify}
'');
}