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:
Bernardo Magri
2026-04-04 10:11:09 +01:00
parent f1ed0d7f47
commit cfd5e4bb65
23 changed files with 378 additions and 173 deletions

View File

@@ -11,8 +11,7 @@ if [[ -z $THEME_NAME ]]; then
fi
STATE_DIR="$HOME/.config/home-manager"
THEME_STATE_FILE="$STATE_DIR/theme-state.nix"
WALLPAPER_STATE_FILE="$STATE_DIR/wallpaper-state.nix"
STATE_FILE="$STATE_DIR/state.json"
# Logic for finding themes
if [ -d "/etc/nixos/nomarchy/themes" ]; then
@@ -24,6 +23,7 @@ else
fi
mkdir -p "$STATE_DIR"
[[ ! -f $STATE_FILE ]] && echo "{}" > "$STATE_FILE"
if [ ! -d "$THEMES_DIR/$THEME_NAME" ] && ! [[ "$THEME_NAME" == "nord" ]]; then
echo "Theme '$THEME_NAME' not found in $THEMES_DIR"
@@ -31,18 +31,23 @@ if [ ! -d "$THEMES_DIR/$THEME_NAME" ] && ! [[ "$THEME_NAME" == "nord" ]]; then
# (Assuming nomarchy-palettes.nix is imported in Nix)
fi
echo "$THEME_NAME" > "$THEME_STATE_FILE"
TMP_JSON=$(mktemp)
jq ".theme = \"$THEME_NAME\"" "$STATE_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$STATE_FILE"
# Try to find a background for this theme
BG_DIR="$THEMES_DIR/$THEME_NAME/backgrounds"
if [ -d "$BG_DIR" ]; then
BG=$(ls "$BG_DIR" | head -n 1)
if [ -n "$BG" ]; then
echo "$BG_DIR/$BG" > "$WALLPAPER_STATE_FILE"
TMP_JSON=$(mktemp)
jq ".wallpaper = \"$BG_DIR/$BG\"" "$STATE_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$STATE_FILE"
fi
fi
echo "Theme set to $THEME_NAME. Applying changes with env-update..."
rm -rf "$HOME/.config/nomarchy/current/theme"
env-update
nomarchy-theme-set-templates
nomarchy-hook theme-set "$THEME_NAME"