From 893fa91fbfd3c5d9dd364468a6da1fd9acaae5dd Mon Sep 17 00:00:00 2001 From: Bernardo Magri Date: Thu, 21 May 2026 20:35:52 +0100 Subject: [PATCH] fix(theme): exit on missing theme; persist bg picks across rebuilds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two related bugs in the theme switcher scripts: (1) nomarchy-theme-set printed a warning when the theme directory didn't exist but kept going — it wrote the bad name into state.json and ran nomarchy-env-update on a broken state. Added an exit 1 after the warning. (2) nomarchy-theme-bg-set updated the live ~/.config/nomarchy/current/ background symlink + restarted swaybg but never wrote state.json. The script is called by the walker background-selector menu (elephant/nomarchy_background_selector.lua) and by the nomarchy- wallpaper CLI wrapper, so every wallpaper picked via either path silently reverted to the active theme's default on the next home-manager switch — themes/engine/files.nix re-resolves config.nomarchy.wallpaper at every rebuild. Now writes the chosen path into state.json's wallpaper field, mirroring nomarchy-theme-bg-next. Also added a file-exists check so a bogus path fails loudly instead of leaving a dangling symlink + a failed swaybg process. --- themes/engine/scripts/nomarchy-theme-bg-set | 24 +++++++++++++++++++-- themes/engine/scripts/nomarchy-theme-set | 3 ++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/themes/engine/scripts/nomarchy-theme-bg-set b/themes/engine/scripts/nomarchy-theme-bg-set index 0877ba3..9fee2e4 100755 --- a/themes/engine/scripts/nomarchy-theme-bg-set +++ b/themes/engine/scripts/nomarchy-theme-bg-set @@ -1,7 +1,12 @@ #!/bin/bash set -e -# Sets the specified image as the current background +# Sets the specified image as the current background. +# Updates state.json so the choice survives the next rebuild — without +# that write, themes/engine/files.nix re-resolves the wallpaper from +# `nomarchy.wallpaper` on the next home-manager switch and silently +# falls back to the active theme's default background, undoing the +# user's pick. if [[ -z $1 ]]; then echo "Usage: nomarchy-theme-bg-set " >&2 @@ -9,7 +14,22 @@ if [[ -z $1 ]]; then fi BACKGROUND="$1" -CURRENT_BACKGROUND_LINK="$HOME/.config/nomarchy/current/background" + +if [[ ! -f "$BACKGROUND" ]]; then + echo "Background image not found: $BACKGROUND" >&2 + exit 1 +fi + +STATE_DIR="$HOME/.config/nomarchy" +STATE_FILE="$STATE_DIR/state.json" +CURRENT_BACKGROUND_LINK="$STATE_DIR/current/background" + +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" # Create symlink to the new background ln -nsf "$BACKGROUND" "$CURRENT_BACKGROUND_LINK" diff --git a/themes/engine/scripts/nomarchy-theme-set b/themes/engine/scripts/nomarchy-theme-set index e067dc7..57e5bb8 100755 --- a/themes/engine/scripts/nomarchy-theme-set +++ b/themes/engine/scripts/nomarchy-theme-set @@ -30,7 +30,8 @@ mkdir -p "$STATE_DIR" [[ ! -f $STATE_FILE ]] && echo "{}" > "$STATE_FILE" if [ ! -d "$THEMES_DIR/$THEME_NAME" ]; then - echo "Theme '$THEME_NAME' not found in $THEMES_DIR" + echo "Theme '$THEME_NAME' not found in $THEMES_DIR" >&2 + exit 1 fi TMP_JSON=$(mktemp)