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"} <