pinwheel: Toggle the work VPN from waybar without sudo
This commit is contained in:
2 files changed
+67
-24
No files matched your search
@@ -87,26 +87,33 @@ let
|
|||||||
esac
|
esac
|
||||||
'';
|
'';
|
||||||
|
|
||||||
work-vpn-status = pkgs.writeShellScript "work-vpn-status" ''
|
work-vpn = pkgs.writeShellScript "work-vpn" ''
|
||||||
ACTIVE_ENVS=""
|
connected() {
|
||||||
|
systemctl is-active --quiet openvpn-work-staging.service openvpn-work-production.service
|
||||||
|
}
|
||||||
|
|
||||||
STAGING_STATUS=$(systemctl is-active openvpn-work-staging.service)
|
output() {
|
||||||
if [ "$STAGING_STATUS" == "active" ]; then
|
if connected; then
|
||||||
ACTIVE_ENVS="S"
|
echo '{ "text": "WORK-VPN ON", "class": "connected" }'
|
||||||
fi
|
|
||||||
|
|
||||||
PRODUCTION_STATUS=$(systemctl is-active openvpn-work-production.service)
|
|
||||||
if [ "$PRODUCTION_STATUS" == "active" ]; then
|
|
||||||
if [ -n "$ACTIVE_ENVS" ]; then
|
|
||||||
ACTIVE_ENVS="$ACTIVE_ENVS&P"
|
|
||||||
else
|
else
|
||||||
ACTIVE_ENVS="P"
|
echo "{ \"text\": \"<span font='16' rise='-3000'></span>\", \"tooltip\": \"Work VPN off\", \"class\": \"disconnected\" }"
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
if [ -n "$ACTIVE_ENVS" ]; then
|
toggle() {
|
||||||
echo "WORK-VPN $ACTIVE_ENVS ON"
|
if connected; then
|
||||||
|
systemctl stop work-vpn.target && ${pkgs.libnotify}/bin/notify-send "Disconnected from work VPN"
|
||||||
|
else
|
||||||
|
systemctl start work-vpn.target && ${pkgs.libnotify}/bin/notify-send "Connected to work VPN"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
--toggle)
|
||||||
|
toggle ;;
|
||||||
|
--output)
|
||||||
|
output ;;
|
||||||
|
esac
|
||||||
'';
|
'';
|
||||||
|
|
||||||
toggle-bt-power = pkgs.writeShellScript "toggle-bt-power" ''
|
toggle-bt-power = pkgs.writeShellScript "toggle-bt-power" ''
|
||||||
@@ -142,20 +149,22 @@ in
|
|||||||
|
|
||||||
modules-left = lib.mkIf hyprlandEnabled [ "hyprland/workspaces" ];
|
modules-left = lib.mkIf hyprlandEnabled [ "hyprland/workspaces" ];
|
||||||
modules-right = [
|
modules-right = [
|
||||||
"custom/work-vpn-status"
|
|
||||||
"custom/music"
|
"custom/music"
|
||||||
"custom/container-status"
|
"custom/container-status"
|
||||||
"custom/dunst"
|
"custom/dunst"
|
||||||
"bluetooth"
|
"bluetooth"
|
||||||
"wireplumber"
|
"wireplumber"
|
||||||
|
"custom/work-vpn"
|
||||||
"custom/tailscale"
|
"custom/tailscale"
|
||||||
"network"
|
"network"
|
||||||
"battery"
|
"battery"
|
||||||
"clock"
|
"clock"
|
||||||
];
|
];
|
||||||
|
|
||||||
"custom/work-vpn-status" = {
|
"custom/work-vpn" = {
|
||||||
exec = "${work-vpn-status}";
|
exec = "${work-vpn} --output";
|
||||||
|
return-type = "json";
|
||||||
|
on-click-right = "${work-vpn} --toggle";
|
||||||
interval = 2;
|
interval = 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -247,12 +256,14 @@ in
|
|||||||
|
|
||||||
modules-left = lib.mkIf hyprlandEnabled [ "hyprland/workspaces" ];
|
modules-left = lib.mkIf hyprlandEnabled [ "hyprland/workspaces" ];
|
||||||
modules-right = [
|
modules-right = [
|
||||||
"custom/work-vpn-status"
|
"custom/work-vpn"
|
||||||
"clock"
|
"clock"
|
||||||
];
|
];
|
||||||
|
|
||||||
"custom/work-vpn-status" = {
|
"custom/work-vpn" = {
|
||||||
exec = "${work-vpn-status}";
|
exec = "${work-vpn} --output";
|
||||||
|
return-type = "json";
|
||||||
|
on-click-right = "${work-vpn} --toggle";
|
||||||
interval = 2;
|
interval = 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -306,10 +317,14 @@ in
|
|||||||
color: #${config.lib.colors.warning};
|
color: #${config.lib.colors.warning};
|
||||||
}
|
}
|
||||||
|
|
||||||
#custom-work-vpn-status {
|
#custom-work-vpn.connected {
|
||||||
color: #${config.lib.colors.warning};
|
color: #${config.lib.colors.warning};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#custom-work-vpn.disconnected {
|
||||||
|
color: #${config.lib.colors.foreground-dim};
|
||||||
|
}
|
||||||
|
|
||||||
#custom-container-status.running {
|
#custom-container-status.running {
|
||||||
color: #${config.lib.colors.warning};
|
color: #${config.lib.colors.warning};
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
|
|||||||
@@ -91,10 +91,10 @@ EOF
|
|||||||
(pkgs.writeShellScriptBin "work-vpn" ''
|
(pkgs.writeShellScriptBin "work-vpn" ''
|
||||||
case $1 in
|
case $1 in
|
||||||
up)
|
up)
|
||||||
sudo sh -c "systemctl start openvpn-work-staging.service; systemctl start openvpn-work-production.service"
|
systemctl start work-vpn.target
|
||||||
;;
|
;;
|
||||||
down)
|
down)
|
||||||
sudo sh -c "systemctl stop openvpn-work-staging.service; systemctl stop openvpn-work-production.service"
|
systemctl stop work-vpn.target
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
'')
|
'')
|
||||||
@@ -142,6 +142,34 @@ EOF
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
systemd.targets.work-vpn = lib.mkIf openvpnEnabled {
|
||||||
|
description = "Work VPN";
|
||||||
|
requires = [
|
||||||
|
"openvpn-work-staging.service"
|
||||||
|
"openvpn-work-production.service"
|
||||||
|
];
|
||||||
|
after = [
|
||||||
|
"openvpn-work-staging.service"
|
||||||
|
"openvpn-work-production.service"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services = lib.mkIf openvpnEnabled {
|
||||||
|
openvpn-work-staging.partOf = [ "work-vpn.target" ];
|
||||||
|
openvpn-work-production.partOf = [ "work-vpn.target" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
security.polkit.extraConfig = lib.mkIf openvpnEnabled ''
|
||||||
|
polkit.addRule(function(action, subject) {
|
||||||
|
if (action.id == "org.freedesktop.systemd1.manage-units" &&
|
||||||
|
subject.user == "alex" &&
|
||||||
|
action.lookup("unit") == "work-vpn.target" &&
|
||||||
|
["start", "stop", "restart"].indexOf(action.lookup("verb")) >= 0) {
|
||||||
|
return polkit.Result.YES;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
'';
|
||||||
|
|
||||||
age.secrets = {
|
age.secrets = {
|
||||||
"work-gitconfig" = lib.mkIf gitEnabled {
|
"work-gitconfig" = lib.mkIf gitEnabled {
|
||||||
file = ../../../../secrets/pinwheel/work-gitconfig.age;
|
file = ../../../../secrets/pinwheel/work-gitconfig.age;
|
||||||
|
|||||||
Reference in new issue
Block a user