feat: replace noctalia with an eww panel (#3)
CI / eval (push) Successful in 2m3s
CI / lint (push) Successful in 29s

This commit was merged in pull request #3.
This commit is contained in:
2026-08-19 15:13:05 +01:00
parent d61700d173
commit a0a69cf58c
16 changed files with 565 additions and 180 deletions
@@ -0,0 +1,292 @@
{
config,
lib,
pkgs,
inputs,
...
}:
let
cfg = config.custom.hyprland;
# Every length in the stylesheet goes through this, so one option resizes the
# whole dashboard for 4K hosts.
px = n: "${toString (builtins.ceil (n * cfg.panelScale))}px";
mkScript =
name: runtimeInputs:
pkgs.writeShellApplication {
inherit name runtimeInputs;
text = builtins.readFile (./scripts + "/${name}.sh");
};
battery = mkScript "battery" [
pkgs.coreutils
pkgs.findutils
pkgs.jq
];
network = mkScript "network" [
pkgs.networkmanager
pkgs.gawk
pkgs.gnused
pkgs.jq
];
bluetooth = mkScript "bluetooth" [
pkgs.bluez
pkgs.coreutils
pkgs.findutils
pkgs.gawk
pkgs.jq
];
audio = mkScript "audio" [
pkgs.gawk
pkgs.jq
pkgs.wireplumber
];
panelToggle = mkScript "eww-panel" [
config.programs.eww.package
pkgs.jq
inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.hyprland
];
eww = lib.getExe config.programs.eww.package;
bluetoothctl = "${pkgs.bluez}/bin/bluetoothctl";
wpctl = "${pkgs.wireplumber}/bin/wpctl";
wpaperctl = "${pkgs.wpaperd}/bin/wpaperctl";
# setsid, and before the close rather than after it: eww kills the onclick
# handler's process group when the window it came from goes away, so a bare
# `close panel; cmd` never reaches cmd.
act = cmd: "${pkgs.util-linux}/bin/setsid --fork ${cmd}; ${eww} close panel";
in
{
home.packages = [
panelToggle
pkgs.waypaper
];
programs.eww = {
enable = true;
systemd.enable = true;
yuckConfig = ''
;; Each script prints one JSON object; widgets read .icon / .label / .sub
;; off it.
(defpoll clock-time :interval "10s" :initial "--:--" `date +%H:%M`)
(defpoll clock-date :interval "1h" :initial "" `date "+%A, %d %B"`)
(defpoll battery
:interval "30s"
:initial '{"present":false,"icon":"","label":"","sub":""}'
`${lib.getExe battery}`)
(defpoll network
:interval "10s"
:initial '{"icon":"","label":"...","sub":""}'
`${lib.getExe network}`)
(defpoll bluetooth
:interval "10s"
:initial '{"powered":false,"icon":"","label":"...","sub":""}'
`${lib.getExe bluetooth}`)
(defpoll speaker
:interval "2s"
:initial '{"present":false,"volume":0,"muted":true,"icon":""}'
`${lib.getExe audio} sink`)
(defpoll mic
:interval "2s"
:initial '{"present":false,"volume":0,"muted":true,"icon":""}'
`${lib.getExe audio} source`)
(defwidget card [title]
(box :class "card" :orientation "v" :space-evenly false
(label :class "card-title" :halign "start" :text title :visible {title != ""})
(box :orientation "v" :space-evenly false
(children))))
(defwidget row [icon label sub onclick]
(eventbox :class "row" :cursor "pointer" :onclick onclick
(box :space-evenly false
(label :class "row-icon" :text icon)
(box :orientation "v" :space-evenly false :hexpand true
(label :class "row-label" :halign "start" :text label)
(label :class "row-sub" :halign "start" :text sub :visible {sub != ""})))))
;; Mute button, slider, readout. `state` is the speaker/mic json object.
(defwidget volume [state node]
(box :space-evenly false :visible {state.present}
(button :class {state.muted ? "mute muted" : "mute"}
:onclick "${wpctl} set-mute ''${node} toggle"
{state.icon})
(scale :class "slider" :hexpand true
:value {state.volume} :min 0 :max 101
:onchange "${wpctl} set-volume ''${node} {}%")
(label :class "row-sub" :text {"''${state.volume}%"})))
(defwidget action [icon tooltip onclick]
(button :class "action" :tooltip tooltip :onclick onclick icon))
(defwidget dashboard []
(box :class "dash" :orientation "v" :space-evenly false
(box :space-evenly false
(card :title ""
(label :class "clock-time" :halign "start" :text clock-time)
(label :class "clock-date" :halign "start" :text clock-date))
(card :title "System"
(box :visible {battery.present} :space-evenly false
(row :icon {battery.icon} :label {battery.label}
:sub {battery.sub} :onclick ""))
(row :icon {network.icon} :label {network.label} :sub {network.sub}
:onclick "${act "${pkgs.networkmanagerapplet}/bin/nm-connection-editor"}")
(row :icon {bluetooth.icon} :label {bluetooth.label} :sub {bluetooth.sub}
:onclick "${act "${pkgs.blueman}/bin/blueman-manager"}")))
(box :space-evenly false
(card :title "Audio"
(volume :state speaker :node "@DEFAULT_AUDIO_SINK@")
(volume :state mic :node "@DEFAULT_AUDIO_SOURCE@"))
(card :title "Actions"
(box :space-evenly false :halign "start"
(action :icon "󰑐" :tooltip "Next wallpaper"
:onclick "${wpaperctl} next")
(action :icon "󰸉" :tooltip "Pick wallpaper"
:onclick "${act "${lib.getExe pkgs.waypaper}"}")
(action :icon "󰂯" :tooltip "Toggle bluetooth"
:onclick {bluetooth.powered
? "${bluetoothctl} power off"
: "${bluetoothctl} power on"})
(action :icon "󰌾" :tooltip "Lock"
:onclick "${act "${pkgs.systemd}/bin/loginctl lock-session"}"))))))
;; Sized to its content. A full-screen backdrop would give click-outside-
;; to-close, but its handler also fires for clicks on the sliders.
(defwindow panel
:namespace "eww-panel"
:geometry (geometry :anchor "center")
:stacking "overlay"
(dashboard))
'';
scssConfig = ''
$bg: rgba(46, 52, 64, 0.96);
$card: rgba(59, 66, 82, 0.72);
$border: #4c566a;
$fg: #eceff4;
$muted: #81a1c1;
$accent: #88c0d0;
$red: #bf616a;
* {
all: unset;
font-family: "FiraCode Nerd Font", monospace;
}
window {
background-color: transparent;
}
.dash {
background-color: $bg;
border: ${px 1} solid $border;
border-radius: ${px 20};
padding: ${px 14};
color: $fg;
}
.card {
background-color: $card;
border-radius: ${px 14};
padding: ${px 16};
margin: ${px 6};
min-width: ${px 300};
}
.card-title {
font-size: ${px 11};
color: $muted;
margin-bottom: ${px 8};
}
.clock-time {
font-size: ${px 56};
font-weight: 600;
}
.clock-date {
font-size: ${px 14};
color: $muted;
}
.row {
border-radius: ${px 10};
padding: ${px 10} ${px 12};
&:hover {
background-color: rgba(136, 192, 208, 0.14);
}
}
.row-icon {
font-size: ${px 22};
color: $accent;
min-width: ${px 34};
}
.row-label {
font-size: ${px 14};
}
.row-sub {
font-size: ${px 11};
color: $muted;
}
.mute {
font-size: ${px 20};
color: $accent;
min-width: ${px 34};
&.muted {
color: $red;
}
}
.slider {
margin: 0 ${px 12};
min-width: ${px 180};
trough {
background-color: rgba(76, 86, 106, 0.6);
border-radius: ${px 8};
min-height: ${px 8};
highlight {
background-color: $accent;
border-radius: ${px 8};
}
}
}
.action {
background-color: rgba(76, 86, 106, 0.45);
border-radius: ${px 12};
padding: ${px 12} ${px 18};
margin-right: ${px 8};
font-size: ${px 20};
color: $fg;
&:hover {
background-color: $accent;
color: #2e3440;
}
}
'';
};
}
@@ -0,0 +1,37 @@
# One JSON object per audio node. $1 is "sink" or "source". wpctl prints
# "Volume: 0.45", with " [MUTED]" appended, and errors when there is no node.
case "$1" in
sink) node="@DEFAULT_AUDIO_SINK@" ;;
source) node="@DEFAULT_AUDIO_SOURCE@" ;;
*) echo "usage: audio sink|source" >&2; exit 2 ;;
esac
raw=$(wpctl get-volume "$node" 2>/dev/null || true)
case "$raw" in
*Volume:*) ;;
*)
jq -nc '{ present: false, volume: 0, muted: true, icon: "󰖁" }'
exit 0
;;
esac
volume=$(printf '%s' "$raw" | awk '{ printf "%d", $2 * 100 }')
muted=false
case "$raw" in *MUTED*) muted=true ;; esac
if [ "$1" = "source" ]; then
if [ "$muted" = true ]; then icon="󰍭"; else icon="󰍬"; fi
elif [ "$muted" = true ]; then icon="󰖁"
elif [ "$volume" -ge 66 ]; then icon="󰕾"
elif [ "$volume" -ge 33 ]; then icon="󰖀"
else icon="󰕿"
fi
jq -nc \
--argjson volume "$volume" \
--argjson muted "$muted" \
--arg icon "$icon" \
'{ present: true, volume: $volume, muted: $muted, icon: $icon }'
@@ -0,0 +1,32 @@
# One JSON object for the panel's battery row. `present: false` on the desktops,
# which have no BAT* at all — the row hides itself on that.
bat=$(find /sys/class/power_supply -maxdepth 1 -name 'BAT*' 2>/dev/null | sort | head -1)
if [ -z "$bat" ]; then
jq -nc '{ present: false, icon: "", label: "", sub: "" }'
exit 0
fi
capacity=$(cat "$bat/capacity")
status=$(cat "$bat/status")
if [ "$status" = "Charging" ] || [ "$status" = "Full" ]; then
icon="󰂄"
elif [ "$capacity" -ge 90 ]; then icon="󰁹"
elif [ "$capacity" -ge 80 ]; then icon="󰂂"
elif [ "$capacity" -ge 70 ]; then icon="󰂁"
elif [ "$capacity" -ge 60 ]; then icon="󰂀"
elif [ "$capacity" -ge 50 ]; then icon="󰁿"
elif [ "$capacity" -ge 40 ]; then icon="󰁾"
elif [ "$capacity" -ge 30 ]; then icon="󰁽"
elif [ "$capacity" -ge 20 ]; then icon="󰁼"
elif [ "$capacity" -ge 10 ]; then icon="󰁻"
else icon="󰁺"
fi
jq -nc \
--arg icon "$icon" \
--arg label "$capacity%" \
--arg sub "$status" \
'{ present: true, icon: $icon, label: $label, sub: $sub }'
@@ -0,0 +1,22 @@
# One JSON object for the panel's bluetooth row. bluetoothctl blocks forever
# instead of erroring when there is no adapter, hence the /sys check + timeouts.
if [ -z "$(find /sys/class/bluetooth -mindepth 1 -maxdepth 1 2>/dev/null)" ]; then
jq -nc '{ powered: false, icon: "󰂲", label: "No adapter", sub: "" }'
exit 0
fi
powered=$(timeout 2 bluetoothctl show 2>/dev/null | awk '/Powered:/ { print $2; exit }' || true)
if [ "$powered" != "yes" ]; then
jq -nc '{ powered: false, icon: "󰂲", label: "Off", sub: "" }'
exit 0
fi
connected=$(timeout 2 bluetoothctl devices Connected 2>/dev/null | cut -d' ' -f3- | paste -sd', ' - || true)
if [ -n "$connected" ]; then
jq -nc --arg sub "$connected" '{ powered: true, icon: "󰂱", label: "On", sub: $sub }'
else
jq -nc '{ powered: true, icon: "󰂯", label: "On", sub: "Nothing connected" }'
fi
@@ -0,0 +1,11 @@
# Toggle the panel on whichever monitor has focus. `eww open --toggle` can't do
# this: it ignores --screen when the window is already open elsewhere, so the
# panel would stay stuck on the monitor it first appeared on.
if eww active-windows | grep -q '^panel'; then
exec eww close panel
fi
screen=$(hyprctl -j monitors | jq -r 'map(select(.focused))[0].id // 0')
exec eww open panel --screen "$screen"
@@ -0,0 +1,43 @@
# One JSON object for the panel's network row. State must match "connected"
# exactly: NetworkManager reports docker0 and br-* as "connected (externally)".
status=$(nmcli -t -f TYPE,STATE,CONNECTION device status 2>/dev/null || true)
# nmcli's terse output backslash-escapes colons inside connection names, so
# rejoin fields 3..NF and unescape rather than taking $3.
pick() {
printf '%s\n' "$status" | awk -F: -v want="$1" '
$1 == want && $2 == "connected" {
name = $3
for (i = 4; i <= NF; i++) name = name ":" $i
print name
exit
}' | sed 's/\\:/:/g'
}
wifi=$(pick wifi)
ethernet=$(pick ethernet)
if [ -n "$wifi" ]; then
signal=$(nmcli -t -f IN-USE,SIGNAL dev wifi 2>/dev/null | awk -F: '$1 == "*" { print $2; exit }' || true)
if [ -z "$signal" ]; then icon="󰤨"
elif [ "$signal" -ge 75 ]; then icon="󰤨"
elif [ "$signal" -ge 50 ]; then icon="󰤥"
elif [ "$signal" -ge 25 ]; then icon="󰤢"
else icon="󰤟"
fi
if [ -n "$signal" ]; then
sub="Wi-Fi · $signal%"
else
sub="Wi-Fi"
fi
jq -nc --arg icon "$icon" --arg label "$wifi" --arg sub "$sub" \
'{ icon: $icon, label: $label, sub: $sub }'
elif [ -n "$ethernet" ]; then
jq -nc --arg label "$ethernet" '{ icon: "󰈀", label: $label, sub: "Ethernet" }'
else
jq -nc '{ icon: "󰤭", label: "Offline", sub: "" }'
fi