Files
Nomarchy/features/scripts/utils/nomarchy-toggle-waybar
Bernardo Magri 055832e916 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.
2026-05-22 18:23:35 +01:00

29 lines
893 B
Bash
Executable File

#!/usr/bin/env bash
set -e
# 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"
[[ ! -f $STATE_FILE ]] && echo "{}" > "$STATE_FILE"
if [[ $NOMARCHY_TOGGLE_WAYBAR == "false" ]]; then
NEW_VALUE="true"
systemctl --user start waybar.service 2>/dev/null || true
notify-send -u low " Top bar enabled"
else
NEW_VALUE="false"
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."