feat(core): migrate system state to unified declarative JSON
- Consolidate all configuration toggles (suspend, idle, waybar, etc.) into ~/.config/home-manager/state.json - Introduce nomarchy.toggles and nomarchy.hyprland options in Nix - Inject toggle states into all bin/ scripts via environment variables - Update toggle scripts to mutate JSON and trigger background rebuilds - Add a migration script to transition legacy flag files to the new format
This commit is contained in:
@@ -1,36 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Toggles the nightlight (hyprsunset) between enabled (4000) and disabled (6500)
|
||||
# Declarative + Hybrid (instant IPC) for Nomarchy NixOS.
|
||||
# Toggles the nightlight (hyprsunset).
|
||||
# Hybrid: updates state.json and provides instant feedback.
|
||||
|
||||
STATE_FILE="$HOME/.config/home-manager/hyprsunset-state.json"
|
||||
STATE_FILE="$HOME/.config/home-manager/state.json"
|
||||
mkdir -p "$(dirname "$STATE_FILE")"
|
||||
|
||||
if [ ! -f "$STATE_FILE" ]; then
|
||||
echo '{"enabled": false, "temperature": 4000}' > "$STATE_FILE"
|
||||
fi
|
||||
# Initialize if doesn't exist
|
||||
[[ ! -f $STATE_FILE ]] && echo "{}" > "$STATE_FILE"
|
||||
|
||||
enabled=$(jq -r '.enabled' "$STATE_FILE")
|
||||
|
||||
if [[ $enabled == "true" ]]; then
|
||||
NEW_ENABLED="false"
|
||||
TEMP=6500
|
||||
notify-send -u low " Nightlight DISABLED"
|
||||
if [[ $NOMARCHY_TOGGLE_NIGHTLIGHT == "false" ]]; then
|
||||
NEW_VALUE="true"
|
||||
hyprctl dispatch exec hyprsunset --temperature 4000
|
||||
notify-send -u low " Nightlight enabled"
|
||||
else
|
||||
NEW_ENABLED="true"
|
||||
TEMP=4000
|
||||
notify-send -u low " Nightlight ENABLED"
|
||||
NEW_VALUE="false"
|
||||
pkill hyprsunset
|
||||
notify-send -u low " Nightlight disabled"
|
||||
fi
|
||||
|
||||
# Instant feedback via IPC
|
||||
if pgrep -x hyprsunset >/dev/null; then
|
||||
hyprctl hyprsunset temperature $TEMP
|
||||
else
|
||||
# Should be started by systemd, but just in case
|
||||
setsid hyprsunset -t $TEMP &
|
||||
fi
|
||||
TMP_JSON=$(mktemp)
|
||||
jq ".nightlight = $NEW_VALUE" "$STATE_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$STATE_FILE"
|
||||
|
||||
echo "{\"enabled\": $NEW_ENABLED, \"temperature\": 4000}" > "$STATE_FILE"
|
||||
echo "Nightlight set to $NEW_ENABLED ($TEMP) declaratively."
|
||||
# No need to run env-update if we don't want the delay,
|
||||
# as next HM switch will pick it up and apply it.
|
||||
echo "Nightlight state set to $NEW_VALUE. Environment will be fully updated on next rebuild."
|
||||
|
||||
Reference in New Issue
Block a user