feat: implement hybrid declarative state with automatic Nix sync
Some checks failed
Check / eval-and-lint (push) Has been cancelled

This commit is contained in:
Bernardo Magri
2026-05-31 20:09:12 +01:00
parent 624023c1d5
commit dc3346bc55
18 changed files with 182 additions and 48 deletions

View File

@@ -24,14 +24,8 @@ mkdir -p "$STATE_DIR"
[[ ! -f $STATE_FILE ]] && echo "{}" > "$STATE_FILE"
if fc-list | grep -iq "$font_name"; then
TMP_JSON=$(mktemp)
jq --arg font "$font_name" '.font = $font' "$STATE_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$STATE_FILE"
echo "Font set to $font_name."
echo "NOTE: This change is TEMPORARY and will be lost on the next system rebuild."
echo "To make this font permanent, add the following to your /etc/nixos/home.nix:"
echo " nomarchy.fonts.monospace = \"$font_name\";"
echo ""
echo "Applying changes with nomarchy-env-update..."
nomarchy-state-write font "$font_name"
echo "Font set to $font_name. Applying changes with nomarchy-env-update..."
if [[ "$no_update" == "true" ]]; then
echo "Skipping nomarchy-env-update due to --no-update flag."

View File

@@ -45,8 +45,7 @@ done
NEXT_INDEX=$(((INDEX + 1) % TOTAL))
NEW_BG="$BG_DIR/${BACKGROUNDS[$NEXT_INDEX]}"
TMP_JSON=$(mktemp)
jq --arg wp "$NEW_BG" '.wallpaper = $wp' "$STATE_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$STATE_FILE"
nomarchy-state-write wallpaper "$NEW_BG"
# Instant feedback via swww
if pgrep -x swww-daemon >/dev/null; then

View File

@@ -28,8 +28,7 @@ mkdir -p "$STATE_DIR"
[[ ! -f $STATE_FILE ]] && echo "{}" > "$STATE_FILE"
# Persist the choice for the next rebuild.
TMP_JSON=$(mktemp)
jq --arg wp "$BACKGROUND" '.wallpaper = $wp' "$STATE_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$STATE_FILE"
nomarchy-state-write wallpaper "$BACKGROUND"
# Create symlink to the new background
ln -nsf "$BACKGROUND" "$CURRENT_BACKGROUND_LINK"

View File

@@ -34,13 +34,12 @@ if [ ! -d "$THEMES_DIR/$THEME_NAME" ]; then
exit 1
fi
TMP_JSON=$(mktemp)
jq --arg theme "$THEME_NAME" '.theme = $theme' "$STATE_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$STATE_FILE"
nomarchy-state-write theme "$THEME_NAME"
# Sync to system state if we have permissions (for system-level theming like browser policies)
SYSTEM_STATE_FILE="/etc/nixos/state.json"
if [ -w "$SYSTEM_STATE_FILE" ] || [ -w "/etc/nixos" ]; then
tmp=$(mktemp); sudo jq --arg theme "$THEME_NAME" '.theme = $theme' "$SYSTEM_STATE_FILE" > "$tmp" 2>/dev/null && sudo mv "$tmp" "$SYSTEM_STATE_FILE" 2>/dev/null || rm -f "$tmp"
nomarchy-state-write --file "$SYSTEM_STATE_FILE" theme "$THEME_NAME"
fi
# Try to find a background for this theme
@@ -48,17 +47,11 @@ BG_DIR="$THEMES_DIR/$THEME_NAME/backgrounds"
if [ -d "$BG_DIR" ]; then
BG=$(ls "$BG_DIR" | head -n 1)
if [ -n "$BG" ]; then
TMP_JSON=$(mktemp)
jq --arg wp "$BG_DIR/$BG" '.wallpaper = $wp' "$STATE_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$STATE_FILE"
nomarchy-state-write wallpaper "$BG_DIR/$BG"
fi
fi
echo "Theme set to $THEME_NAME."
echo "NOTE: This change is TEMPORARY and will be lost on the next system rebuild."
echo "To make this theme permanent, add the following to your /etc/nixos/home.nix:"
echo " nomarchy.theme = \"$THEME_NAME\";"
echo ""
echo "Applying changes with nomarchy-env-update..."
echo "Theme set to $THEME_NAME. Applying changes with nomarchy-env-update..."
if [[ "$NO_UPDATE" == "true" ]]; then
echo "Skipping nomarchy-env-update due to --no-update flag."

View File

@@ -25,7 +25,6 @@ else
notify-send -u low " Nightlight disabled"
fi
TMP_JSON=$(mktemp)
jq --argjson val "$NEW_VALUE" '.nightlight = $val' "$STATE_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$STATE_FILE"
nomarchy-state-write nightlight "$NEW_VALUE" --type bool
echo "Nightlight state set to $NEW_VALUE."