refactor(waybar): move modules to owners

This commit is contained in:
2026-10-11 19:53:18 -04:00
parent 64f1db737d
commit 66bbfe80c7
5 changed files with 109 additions and 83 deletions

View File

@@ -5,6 +5,9 @@
...
}:
# PipeWire as the desktop audio server.
let
glyph = code: builtins.fromJSON ''"\u${code}"'';
in
{
options.modules.desktop.utilities.audio.enable = lib.mkEnableOption "the PipeWire audio server";
@@ -15,7 +18,7 @@
locked = true;
action = {
kind = "exec";
command = "${pkgs.playerctl}/bin/playerctl play-pause";
command = "${lib.getExe pkgs.playerctl} play-pause";
};
};
@@ -24,7 +27,7 @@
locked = true;
action = {
kind = "exec";
command = "${pkgs.playerctl}/bin/playerctl next";
command = "${lib.getExe pkgs.playerctl} next";
};
};
@@ -33,7 +36,35 @@
locked = true;
action = {
kind = "exec";
command = "${pkgs.playerctl}/bin/playerctl previous";
command = "${lib.getExe pkgs.playerctl} previous";
};
};
};
registry.waybar.${config.networking.hostName} = {
mpris = {
order = 30;
settings = {
format = "${glyph "f001"} {title}";
format-paused = "${glyph "f04c"} {title}";
max-length = 40;
on-click = "play-pause";
on-scroll-up = "next";
on-scroll-down = "previous";
};
};
wireplumber = {
order = 40;
settings = {
format = "{icon} {volume}%";
format-muted = "${glyph "f026"} muted";
format-icons = [
(glyph "f026")
(glyph "f027")
(glyph "f028")
];
on-click = "${lib.getExe' pkgs.wireplumber "wpctl"} set-mute @DEFAULT_AUDIO_SINK@ toggle";
};
};
};

View File

@@ -0,0 +1,57 @@
{
config,
lib,
pkgs,
...
}:
# Desktop network status integrations.
let
glyph = code: builtins.fromJSON ''"\u${code}"'';
networkStatus = pkgs.writeShellScript "waybar-network-status" ''
active=$(
${lib.getExe' pkgs.networkmanager "nmcli"} -t -f DEVICE,TYPE,STATE,CONNECTION device status \
| ${lib.getExe' pkgs.gawk "awk"} -F: '$3 == "connected" && $2 != "loopback" { print; exit }'
)
if [ -z "$active" ]; then
${lib.getExe pkgs.jq} -cn \
--arg text "${glyph "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="${glyph "f1eb"}" ;;
ethernet) icon="LAN" ;;
*) icon="NET" ;;
esac
ipaddr=$(${lib.getExe' pkgs.iproute2 "ip"} -4 -o addr show dev "$device" | ${lib.getExe' pkgs.gawk "awk"} '{ print $4; exit }')
${lib.getExe pkgs.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.utilities.network.enable =
lib.mkEnableOption "desktop network status integration";
config = lib.mkIf config.modules.desktop.utilities.network.enable {
registry.waybar.${config.networking.hostName}."custom/network" = {
order = 60;
settings = {
return-type = "json";
exec = "${networkStatus}";
interval = 5;
};
};
};
}