fix(nixos): improve waybar network display

This commit is contained in:
2026-09-04 22:58:20 -04:00
parent ff6495d50a
commit 55c5fdf1bc

View File

@@ -47,6 +47,38 @@ let
printf '{"text":"","class":"idle"}\n'
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
{
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.
systemd.enable = true;
style = ''
.modules-right {
margin-right: 8px;
}
#custom-dnd {
margin-right: 8px;
}
'';
settings.mainBar = {
layer = "top";
position = "top";
height = 30;
spacing = 8;
modules-left = [ "hyprland/workspaces" ];
modules-center = [ "clock" ];
@@ -75,7 +118,7 @@ in
"custom/idle-lock"
"mpris"
"wireplumber"
"network"
"custom/network"
"battery"
"custom/dnd"
];
@@ -128,11 +171,10 @@ in
on-click = "${pkgs.wireplumber}/bin/wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle";
};
network = {
format-wifi = "${g "f1eb"} {essid}";
format-ethernet = "${g "f796"} {ifname}";
format-disconnected = "${g "f127"} off";
tooltip-format = "{ipaddr} via {gwaddr}";
"custom/network" = {
return-type = "json";
exec = "${networkStatus}";
interval = 5;
};
battery = {