diff --git a/hosts/pinwheel/configuration.nix b/hosts/pinwheel/configuration.nix index 4e06ead..396f8a8 100644 --- a/hosts/pinwheel/configuration.nix +++ b/hosts/pinwheel/configuration.nix @@ -25,6 +25,7 @@ ./modules/bemenu ./modules/syncthing ./modules/firefox + ./modules/mullvad ./modules/calibre ./modules/go ./modules/nix diff --git a/hosts/pinwheel/modules/mullvad/default.nix b/hosts/pinwheel/modules/mullvad/default.nix new file mode 100644 index 0000000..09e372a --- /dev/null +++ b/hosts/pinwheel/modules/mullvad/default.nix @@ -0,0 +1,4 @@ +{ ... }: +{ + services.mullvad-vpn.enable = true; +} diff --git a/hosts/pinwheel/modules/waybar/default.nix b/hosts/pinwheel/modules/waybar/default.nix index f1685e9..03b44b8 100644 --- a/hosts/pinwheel/modules/waybar/default.nix +++ b/hosts/pinwheel/modules/waybar/default.nix @@ -33,6 +33,52 @@ let fi ''; + mullvad = pkgs.writeShellScript "mullvad" '' + STATUS_DISCONNECTING="Disconnecting" + STATUS_DISCONNECTED="Disconnected" + STATUS_CONNECTING="Connecting" + STATUS_CONNECTED="Connected" + + status() { + STATUS=$(${pkgs.mullvad}/bin/mullvad status | awk '{print $1}') + echo $STATUS + } + + output() { + case $(status) in + $STATUS_DISCONNECTED) + echo '{ "text": "" }' ;; + $STATUS_CONNECTING) + echo '{ "text": "", "tooltip": "Connecting" }' ;; + $STATUS_CONNECTED) + TOOLTIP=$(${pkgs.mullvad}/bin/mullvad status) + echo "{ \"text\": \"\", \"tooltip\":\"$TOOLTIP\" }" ;; + $STATUS_DISCONNECTING) + echo '{ "text": "", "tooltip": "Disconnecting" }' ;; + *) + echo '{ "text": "", "tooltip": "Status unknown" }' ;; + esac + } + + toggle() { + CURRENT_STATUS=$(status) + + case "$CURRENT_STATUS" in + $STATUS_DISCONNECTED) + ${pkgs.mullvad}/bin/mullvad connect --wait > /dev/null && notify-send "Connected to VPN";; + $STATUS_CONNECTED) + ${pkgs.mullvad}/bin/mullvad disconnect --wait > /dev/null && notify-send "Disconnected from VPN";; + esac + } + + case $1 in + --toggle) + toggle ;; + --output) + output ;; + esac + ''; + toggle-bt-power = pkgs.writeShellScript "toggle-bt-power" '' POWERED_ON=$(bluetoothctl show | grep "Powered: yes") if [ -z "$POWERED_ON" ]; then @@ -58,7 +104,7 @@ in output = [ "eDP-1" ]; modules-left = [ "hyprland/workspaces" ]; - modules-right = [ "custom/spotify" "custom/dunst" "bluetooth" "wireplumber" "network" "battery" "clock" ]; + modules-right = [ "custom/spotify" "custom/dunst" "custom/mullvad" "bluetooth" "wireplumber" "network" "battery" "clock" ]; "custom/spotify" = { exec = spotify-status; @@ -74,6 +120,13 @@ in tooltip = false; }; + "custom/mullvad" = { + exec = "${mullvad} --output"; + return-type = "json"; + on-click-right = "${mullvad} --toggle"; + interval = 1; + }; + bluetooth = { "format-off" = "󰂲"; "format-on" = "";