fix(waybar): gate enable on toggles.waybar (Nix-level, not session-local)

features/desktop/waybar/default.nix previously set
`programs.waybar.{enable,systemd.enable} = lib.mkDefault true`
unconditionally. The toggle script wrote .waybar to state.json and
pkill/exec'd waybar for instant feedback, but the next rebuild
re-enabled it because the Nix module didn't read the toggle. Result:
the bar came back on every rebuild/reboot regardless of the persisted
state — inconsistent with toggles.idle (gates services.hypridle.enable)
and now toggles.nightlight (gates services.hyprsunset.enable).

programs.waybar.{enable,systemd.enable} now follow
config.nomarchy.toggles.waybar. nomarchy-toggle-waybar flips the
running systemd user unit (`systemctl --user start/stop waybar.service`)
for instant feedback and writes .waybar back to state.json so the next
rebuild realigns. Disabled toggle now means no waybar across rebuilds
+ reboots, matching the option's documented meaning ("Whether the top
bar is enabled").

`nix flake check --no-build` + `bash -n` clean.
This commit is contained in:
Bernardo Magri
2026-05-22 18:23:35 +01:00
parent 161542c420
commit 055832e916
3 changed files with 13 additions and 9 deletions

View File

@@ -37,8 +37,11 @@ let
in
{
programs.waybar = {
enable = lib.mkDefault true;
systemd.enable = lib.mkDefault true;
# Gated on nomarchy.toggles.waybar — symmetric with services.hypridle
# (toggles.idle) and services.hyprsunset (toggles.nightlight). Disabled
# toggle means no waybar unit, so the bar stays hidden across rebuilds.
enable = lib.mkDefault config.nomarchy.toggles.waybar;
systemd.enable = lib.mkDefault config.nomarchy.toggles.waybar;
settings = lib.mkDefault [ settings ];
style = lib.mkDefault (builtins.readFile styleFile);

View File

@@ -1,27 +1,28 @@
#!/usr/bin/env bash
set -e
# Toggles the waybar top bar.
# Hybrid: updates state.json and provides instant feedback.
# Toggles the waybar top bar. Writes the new state to state.json (so the
# next home-manager rebuild realigns programs.waybar.enable via
# features/desktop/waybar/default.nix) and flips the running systemd
# user unit for instant feedback.
STATE_DIR="$HOME/.config/nomarchy"
STATE_FILE="$STATE_DIR/state.json"
mkdir -p "$STATE_DIR"
# Initialize if doesn't exist
[[ ! -f $STATE_FILE ]] && echo "{}" > "$STATE_FILE"
if [[ $NOMARCHY_TOGGLE_WAYBAR == "false" ]]; then
NEW_VALUE="true"
uwsm-app -- waybar >/dev/null 2>&1 &
systemctl --user start waybar.service 2>/dev/null || true
notify-send -u low " Top bar enabled"
else
NEW_VALUE="false"
pkill -x waybar
systemctl --user stop waybar.service 2>/dev/null || true
notify-send -u low " Top bar disabled"
fi
TMP_JSON=$(mktemp)
jq --argjson val "$NEW_VALUE" '.waybar = $val' "$STATE_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$STATE_FILE"
echo "Waybar state set to $NEW_VALUE. Environment will be fully updated on next rebuild."
echo "Waybar state set to $NEW_VALUE."