pinwheel: Add tailscale module to waybar
This commit is contained in:
@@ -40,6 +40,50 @@ let
|
||||
fi
|
||||
'';
|
||||
|
||||
tailscale = pkgs.writeShellScript "tailscale" ''
|
||||
STATUS_STOPPED="Tailscale is stopped."
|
||||
|
||||
output() {
|
||||
STATUS=$(tailscale status)
|
||||
|
||||
case $STATUS in
|
||||
$STATUS_STOPPED)
|
||||
echo '{ "text": "", "class": "disconnected" }' ;;
|
||||
*)
|
||||
EXIT_NODE=$(tailscale status --json | ${pkgs.jq}/bin/jq .ExitNodeStatus)
|
||||
|
||||
EXIT_NODE_ONLINE=$(echo $EXIT_NODE | ${pkgs.jq}/bin/jq .Online)
|
||||
if [ "$EXIT_NODE_ONLINE" == "null" ]; then
|
||||
echo '{ "text": "", "class": "disconnected" }'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
EXIT_NODE_ID=$(echo $EXIT_NODE | ${pkgs.jq}/bin/jq .ID)
|
||||
EXIT_NODE_NAME=$(tailscale status --json | ${pkgs.jq}/bin/jq ".Peer.[] | select(.ID == $EXIT_NODE_ID) | .HostName")
|
||||
echo "{ \"text\": \"\", \"tooltip\": $EXIT_NODE_NAME }"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
toggle-exit-node() {
|
||||
PREFERRED_EXIT_NODE=$(${pkgs.coreutils}/bin/cat ${config.age.secrets.tailscale-preferred-exit-node.path})
|
||||
|
||||
EXIT_NODE_ONLINE=$(tailscale status --json | ${pkgs.jq}/bin/jq .ExitNodeStatus.Online)
|
||||
if [ "$EXIT_NODE_ONLINE" == "true" ]; then
|
||||
tailscale set --exit-node="" && ${pkgs.libnotify}/bin/notify-send "Disconnected from Exit Node"
|
||||
else
|
||||
tailscale set --exit-node=$PREFERRED_EXIT_NODE && ${pkgs.libnotify}/bin/notify-send "Connected to Exit Node"
|
||||
fi
|
||||
}
|
||||
|
||||
case $1 in
|
||||
--toggle-exit-node)
|
||||
toggle-exit-node ;;
|
||||
--output)
|
||||
output ;;
|
||||
esac
|
||||
'';
|
||||
|
||||
mullvad = pkgs.writeShellScript "mullvad" ''
|
||||
STATUS_DISCONNECTING="Disconnecting"
|
||||
STATUS_DISCONNECTED="Disconnected"
|
||||
@@ -134,6 +178,7 @@ in
|
||||
"custom/mullvad"
|
||||
"bluetooth"
|
||||
"wireplumber"
|
||||
"custom/tailscale"
|
||||
"network"
|
||||
"battery"
|
||||
"clock"
|
||||
@@ -164,6 +209,13 @@ in
|
||||
tooltip = false;
|
||||
};
|
||||
|
||||
"custom/tailscale" = {
|
||||
exec = "${tailscale} --output";
|
||||
return-type = "json";
|
||||
on-click-right = "${tailscale} --toggle-exit-node";
|
||||
interval = 2;
|
||||
};
|
||||
|
||||
"custom/mullvad" = {
|
||||
exec = "${mullvad} --output";
|
||||
return-type = "json";
|
||||
@@ -279,6 +331,14 @@ in
|
||||
color: #${config.lib.colors.warning};
|
||||
}
|
||||
|
||||
#custom-tailscale {
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
#custom-tailscale.disconnected {
|
||||
color: #${config.lib.colors.warning};
|
||||
}
|
||||
|
||||
#custom-mullvad.disconnected {
|
||||
color: #${config.lib.colors.warning};
|
||||
}
|
||||
@@ -298,4 +358,12 @@ in
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
age.secrets = {
|
||||
"tailscale-preferred-exit-node" = {
|
||||
file = ../../../../secrets/pinwheel/tailscale-preferred-exit-node.age;
|
||||
owner = "alex";
|
||||
group = "users";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user