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

@@ -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."