2024-06-26 12:06:44 -06:00
|
|
|
{ pkgs, lib, config, ... }:
|
2024-06-26 12:03:51 -06:00
|
|
|
let
|
|
|
|
cfg = config.services.lock-action;
|
|
|
|
dbus-monitor = "${pkgs.dbus}/bin/dbus-monitor";
|
|
|
|
awk = "${pkgs.gawk}/bin/awk";
|
|
|
|
ssh-add = "${pkgs.openssh}/bin/ssh-add";
|
|
|
|
action-script = pkgs.writeScript "action-script" ''
|
2024-06-26 12:06:44 -06:00
|
|
|
export DBUS_SESSION_BUS_ADDRESS="$(systemctl --user show-environment | ${awk} -F= '/^DBUS_SESSION_BUS_ADDRESS/ {print $(NF-1) "=" $NF}')"
|
|
|
|
export SSH_AUTH_SOCK="$(systemctl --user show-environment | ${awk} -F= '/^SSH_AUTH_SOCK/ {print $NF}')"
|
2024-06-26 12:03:51 -06:00
|
|
|
|
2024-06-26 12:06:44 -06:00
|
|
|
echo $DBUS_SESSION_BUS_ADDRESS
|
|
|
|
echo $SSH_AUTH_SOCK
|
2024-06-26 12:03:51 -06:00
|
|
|
|
2024-06-26 12:06:44 -06:00
|
|
|
${dbus-monitor} --session "type='signal',interface='org.freedesktop.ScreenSaver'" | \
|
|
|
|
while read x; do
|
|
|
|
case "$x" in
|
|
|
|
*"boolean true"*)
|
|
|
|
echo "Screen Locked";
|
|
|
|
${ssh-add} -D
|
|
|
|
/run/wrappers/bin/sudo -K
|
|
|
|
esac
|
|
|
|
done
|
2024-06-26 12:03:51 -06:00
|
|
|
|
2024-06-26 12:06:44 -06:00
|
|
|
'';
|
|
|
|
in
|
2024-06-26 12:03:51 -06:00
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.lock-action = {
|
|
|
|
enable = lib.mkEnableOption "Enable lock actions";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
systemd.user.services.lock-action = {
|
|
|
|
enable = true;
|
|
|
|
script = ''
|
|
|
|
${action-script}
|
|
|
|
'';
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
DBUS_SESSION_BUS_ADDRESS = "fake";
|
|
|
|
SSH_AUTH_SOCK = "fake";
|
|
|
|
};
|
|
|
|
|
|
|
|
wants = [ "graphical-session.target" ];
|
|
|
|
partOf = [ "graphical-session.target" ];
|
|
|
|
after = [ "graphical-session.target" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|