fix(nixos): improve waybar network display
This commit is contained in:
@@ -47,6 +47,38 @@ let
|
|||||||
printf '{"text":"","class":"idle"}\n'
|
printf '{"text":"","class":"idle"}\n'
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
networkStatus = pkgs.writeShellScript "waybar-network-status" ''
|
||||||
|
active=$(
|
||||||
|
${pkgs.networkmanager}/bin/nmcli -t -f DEVICE,TYPE,STATE,CONNECTION device status \
|
||||||
|
| ${pkgs.gawk}/bin/awk -F: '$3 == "connected" && $2 != "loopback" { print; exit }'
|
||||||
|
)
|
||||||
|
|
||||||
|
if [ -z "$active" ]; then
|
||||||
|
${pkgs.jq}/bin/jq -cn \
|
||||||
|
--arg text "${g "f127"} off" \
|
||||||
|
--arg tooltip "Network disconnected" \
|
||||||
|
--arg class "disconnected" \
|
||||||
|
'{ text: $text, tooltip: $tooltip, class: $class }'
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
IFS=: read -r device type _state connection <<< "$active"
|
||||||
|
|
||||||
|
case "$type" in
|
||||||
|
wifi) icon="${g "f1eb"}" ;;
|
||||||
|
ethernet) icon="LAN" ;;
|
||||||
|
*) icon="NET" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
ipaddr=$(${pkgs.iproute2}/bin/ip -4 -o addr show dev "$device" | ${pkgs.gawk}/bin/awk '{ print $4; exit }')
|
||||||
|
|
||||||
|
${pkgs.jq}/bin/jq -cn \
|
||||||
|
--arg text "$icon $connection" \
|
||||||
|
--arg tooltip "$device: ''${ipaddr:-no IPv4}" \
|
||||||
|
--arg class "$type" \
|
||||||
|
'{ text: $text, tooltip: $tooltip, class: $class }'
|
||||||
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.modules.desktop.session.waybar.enable = lib.mkEnableOption "the Waybar status bar";
|
options.modules.desktop.session.waybar.enable = lib.mkEnableOption "the Waybar status bar";
|
||||||
@@ -63,10 +95,21 @@ in
|
|||||||
# so the bar comes up with the session and no compositor exec-once.
|
# so the bar comes up with the session and no compositor exec-once.
|
||||||
systemd.enable = true;
|
systemd.enable = true;
|
||||||
|
|
||||||
|
style = ''
|
||||||
|
.modules-right {
|
||||||
|
margin-right: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#custom-dnd {
|
||||||
|
margin-right: 8px;
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
|
||||||
settings.mainBar = {
|
settings.mainBar = {
|
||||||
layer = "top";
|
layer = "top";
|
||||||
position = "top";
|
position = "top";
|
||||||
height = 30;
|
height = 30;
|
||||||
|
spacing = 8;
|
||||||
|
|
||||||
modules-left = [ "hyprland/workspaces" ];
|
modules-left = [ "hyprland/workspaces" ];
|
||||||
modules-center = [ "clock" ];
|
modules-center = [ "clock" ];
|
||||||
@@ -75,7 +118,7 @@ in
|
|||||||
"custom/idle-lock"
|
"custom/idle-lock"
|
||||||
"mpris"
|
"mpris"
|
||||||
"wireplumber"
|
"wireplumber"
|
||||||
"network"
|
"custom/network"
|
||||||
"battery"
|
"battery"
|
||||||
"custom/dnd"
|
"custom/dnd"
|
||||||
];
|
];
|
||||||
@@ -128,11 +171,10 @@ in
|
|||||||
on-click = "${pkgs.wireplumber}/bin/wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle";
|
on-click = "${pkgs.wireplumber}/bin/wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle";
|
||||||
};
|
};
|
||||||
|
|
||||||
network = {
|
"custom/network" = {
|
||||||
format-wifi = "${g "f1eb"} {essid}";
|
return-type = "json";
|
||||||
format-ethernet = "${g "f796"} {ifname}";
|
exec = "${networkStatus}";
|
||||||
format-disconnected = "${g "f127"} off";
|
interval = 5;
|
||||||
tooltip-format = "{ipaddr} via {gwaddr}";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
battery = {
|
battery = {
|
||||||
|
|||||||
Reference in New Issue
Block a user