From 6331357b45eb73edf3312d73f8f618fe406f43ef Mon Sep 17 00:00:00 2001 From: magic_rb Date: Sat, 23 Dec 2023 20:01:59 +0100 Subject: [PATCH] Add login notify module Signed-off-by: magic_rb --- nixos/modules/notify-login.nix | 121 +++++++++++++++++++++++++++++ nixos/systems/blowhole/default.nix | 11 +++ 2 files changed, 132 insertions(+) create mode 100644 nixos/modules/notify-login.nix diff --git a/nixos/modules/notify-login.nix b/nixos/modules/notify-login.nix new file mode 100644 index 0000000..9184458 --- /dev/null +++ b/nixos/modules/notify-login.nix @@ -0,0 +1,121 @@ +{ + config, + lib, + pkgs, + ... +}: let + cfg = config.services.notify-login; + inherit + (lib) + mkEnableOption + getExe + getExe' + mkIf + mkMerge + mkOption + types + error + optionalString + ; + source = { + name, + pamService, + sessionName, + }: { + options = { + enable = mkEnableOption "Enable login notifications."; + method = mkOption { + type = with types; enum ["matrix"]; + description = '' + What notification method to use. + ''; + }; + settings = let + methodSettings = { + "matrix" = { + secretsFile = mkOption { + type = with types; str; + description = '' + Path to the secrets file. + ''; + }; + stateDirectory = mkOption { + type = with types; str; + description = '' + Path to the state directory. + ''; + }; + markdown = mkOption { + type = with types; bool; + description = '' + Whether to parse input as markdown; + ''; + }; + }; + }; + in + methodSettings.${cfg.${name}.method} or (error "Invalid method"); + }; + config = mkIf cfg.${name}.enable { + security.pam.services.${pamService}.rules.session.pam_exec = let + methods = { + "matrix" = pkgs.writeShellScript "matrix-${name}-notify" '' + { + if [ "$PAM_TYPE" = "open_session" ] ; then + ${getExe' pkgs.coreutils "cat"} <