Home-manager: Add waybar mullvad vpn module

This commit is contained in:
Zeph Levy 2026-05-07 11:47:55 +02:00
parent 46362ce186
commit 9d2bc8aa10
3 changed files with 203 additions and 1 deletions

24
LICENSE Normal file
View file

@ -0,0 +1,24 @@
This repository uses code from @dottmp on github,
for the Mullvad VPN waybar module.
MIT License
Copyright (c) 2026 dottmp
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,142 @@
#!/run/current-system/sw/bin/bash
# CREDIT TO @dottmp on Github (https://github.com/dottmp/mullvad-waybar-module/blob/main/mullvad.sh)
# LICENSED UNDER MIT:
# MIT License
# Copyright (c) 2026 dottmp
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
# Mullvad CLI
#
# Manage the Mullvad VPN daemon via a convenient CLI
# Usage: mullvad <COMMAND>
#
# Commands:
# account Control and display information about your Mullvad account
# auto-connect Control the daemon auto-connect setting
# beta-program Receive notifications about beta updates
# lockdown-mode Control whether to block network access when disconnected from VPN
# dns Configure DNS servers to use when connected
# lan Control the allow local network sharing setting
# connect Connect to a VPN relay
# disconnect Disconnect from the VPN
# reconnect Reconnect to any matching VPN relay
# relay Manage relay and tunnel constraints
# api-access Manage Mullvad API access methods
# obfuscation Manage use of obfuscation protocols for WireGuard. Can make WireGuard traffic look like something else on the network. Helps circumvent censorship and to establish a tunnel when on restricted networks
# split-tunnel Manage split tunneling. To launch applications outside the tunnel, use the program 'mullvad-exclude' instead of this command
# status Return the state of the VPN tunnel
# tunnel Manage tunnel options
# version Show information about the current Mullvad version and available versions
# factory-reset Reset settings, caches, and logs
# reset-settings Reset settings only, but remain logged in and keep logs and caches
# custom-list Manage custom lists
# import-settings Apply a JSON patch generated by 'export-settings'
# export-settings Export a JSON patch based on the current settings
# help Print this message or the help of the given subcommand(s)
# @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
# Mullvad Methods
vpn_get_status() {
mullvad status
}
vpn_reconnect() {
mullvad reconnect
}
vpn_disconnect() {
mullvad disconnect
}
vpn_connect() {
mullvad connect
}
# @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
# Vars
VPN_STATUS="$(vpn_get_status)"
VPN_CONNECTION=$(echo "$VPN_STATUS" | head -n1 | xargs)
VPN_RELAY=$(echo "$VPN_STATUS" | awk -F'Relay: ' '/Relay:/ {print $2}' | xargs)
VPN_FEATURES=$(echo "$VPN_STATUS" | awk -F'Features: ' '/Features:/ {print $2}' | xargs)
VPN_VISIBLE_LOCATION=$(echo "$VPN_STATUS" | awk -F'Visible location: ' '/Visible location:/ {print $2}' | xargs)
# @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
# Actions
#
# [toggle_connection] Connect/disconnect to a VPN relay based on current status and send notification
toggle_connection() {
if [ "$VPN_CONNECTION" = "Connected" ]; then
vpn_disconnect
else
vpn_connect
fi
notify-send
sleep 1
}
# [reconnect] Reconnect to any matching VPN relay and send notification
reconnect() {
vpn_reconnect
notify-send
sleep 1
}
# [get_module_data] Get data for custom/mullvad module in waybar. Returns waybar JSON
get_module_data() {
local class alt tooltip
tooltip="Mullvad VPN\n\nStatus: $VPN_CONNECTION\nRelay: $VPN_RELAY\nFeatures: $VPN_FEATURES\nVisible Location: $VPN_VISIBLE_LOCATION"
case "$VPN_CONNECTION" in
Connected)
class="connected"
alt="connected"
;;
Connecting)
class="connecting"
alt="connecting"
;;
*)
class="disconnected"
alt="disconnected"
;;
esac
echo "{\"text\": \"$VPN_CONNECTION\", \"tooltip\": \"$tooltip\", \"alt\": \"$alt\", \"class\": \"$class\"}"
}
# @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
# Input
case "$1" in
toggle) toggle_connection ;;
reconnect) reconnect ;;
*) get_module_data ;;
esac

View file

@ -11,7 +11,8 @@
modules-left = [
"hyprland/workspaces"
"niri/workspaces"
"niri/window"
# "niri/window"
"custom/mullvad"
];
modules-center = [ "clock" ];
modules-right = [
@ -21,6 +22,22 @@
"battery"
];
"custom/mullvad" = {
"format" = "{icon}";
"exec" = "/home/zeph/nix/home-manager/modules/hypr/mullvad.sh";
"interval" = 10;
"return-type" = "json";
"on-click" = "/home/zeph/nix/home-manager/modules/hypr/mullvad.sh toggle";
"on-click-middle" = "mullvad-vpn";
"on-click-right" = "/home/zeph/nix/home-manager/modules/hypr/mullvad.sh reconnect";
"format-icons" = {
"connected" = "";
"connecting" = "";
"disconnected" = "";
};
"tooltip" = true;
};
"hyprland/workspaces" = {
disable-scroll = true;
all-outputs = true;
@ -89,6 +106,25 @@
@define-color purple #b16286;
@define-color aqua #689d6a;
@define-color orange #d65d0e;
@define-color error #F96184;
@define-color foreground #D3D9FF;
@define-color success #01D38F;
#custom-mullvad {
background-color: @bg1;
min-width: 14px;
margin: 3px 2px;
padding: 2px 6px;
border: 2px solid @orange;
border-radius: 0;
}
#custom-mullvad.connecting {
color: @foreground;
}
#custom-mullvad.connected {
color: @success;
}
* {
font-family: "JetBrainsMono Nerd Font", monospace;