refactor: implement component-based architecture for enhanced maintainability

- Reorganize directory structure into core/, features/, and themes/
- Colocate application Nix logic, configs, scripts, and theme overrides
- Implement 'Inversion of Control' for theming: apps now pull theme-specific layouts
- Update flake.nix and shared library paths to match the new structure
- Document the new Feature-Centric architecture in README.md
This commit is contained in:
Bernardo Magri
2026-04-12 14:51:15 +01:00
parent a9ee79a5ce
commit bbdf34ced8
535 changed files with 119 additions and 127 deletions

View File

@@ -0,0 +1,6 @@
#!/bin/bash
# Returns the name of the current monospace font being used by extracting it from the Waybar stylesheet.
# This can be changed using nomarchy-font-set.
grep -oP 'font-family:\s*["'\'']?\K[^;"'\'']+' ~/.config/waybar/style.css | head -n1

View File

@@ -0,0 +1,5 @@
#!/bin/bash
# Returns a list of all the monospace fonts available on the system that can be set using nomarchy-font-set.
fc-list :spacing=100 -f "%{family[0]}\n" | grep -v -i -E 'emoji|signwriting|nomarchy' | sort -u

View File

@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# Set the system-wide monospace font that should be used by the terminal, hyprlock, waybar, swayosd, etc.
# Declarative version for Nomarchy NixOS.
font_name="$1"
if [[ -z $font_name ]]; then
echo "Usage: nomarchy-font-set <font-name>"
exit 1
fi
STATE_DIR="$HOME/.config/nomarchy"
STATE_FILE="$STATE_DIR/state.json"
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 declaratively. Applying changes..."
env-update
# Instant feedback for certain apps via IPC
if pgrep -x kitty; then
pkill -USR1 kitty
fi
if pgrep -x ghostty; then
pkill -SIGUSR2 ghostty
notify-send -u low " You must restart Ghostty to see font change"
fi
nomarchy-hook font-set "$font_name"
else
echo "Font '$font_name' not found."
exit 1
fi

View File

@@ -0,0 +1,7 @@
#!/bin/bash
# Display a "Done!" message with a spinner and wait for user to press any key.
# Used by various install scripts to indicate completion.
echo
gum spin --spinner "globe" --title "Done! Press any key to close..." -- bash -c 'read -n 1 -s'

View File

@@ -0,0 +1,9 @@
#!/bin/bash
# Display the Nomarchy logo in the terminal using green color.
# Used by various presentation scripts to show branding.
clear
echo -e "\033[32m"
cat < ~/.config/nomarchy/branding/logo.txt
echo -e "\033[0m"

View File

@@ -0,0 +1,7 @@
#!/bin/bash
CURRENT_THEME_NAME=$(cat "$HOME/.config/nomarchy/current/theme.name")
THEME_USER_BACKGROUNDS="$HOME/.config/nomarchy/backgrounds/$CURRENT_THEME_NAME"
mkdir -p "$THEME_USER_BACKGROUNDS"
nautilus "$THEME_USER_BACKGROUNDS"

View File

@@ -0,0 +1,57 @@
#!/usr/bin/env bash
# Cycles through the background images available for the current theme.
# Declarative + Hybrid (instant swww) for Nomarchy NixOS.
STATE_DIR="$HOME/.config/nomarchy"
STATE_FILE="$STATE_DIR/state.json"
mkdir -p "$STATE_DIR"
[[ ! -f $STATE_FILE ]] && echo "{}" > "$STATE_FILE"
THEME_NAME=$(jq -r '.theme // "nord"' "$STATE_FILE")
# Resolve themes directory (Built-in from Nix store via Home Manager, or user extra)
if [ -d "$HOME/.config/nomarchy/themes/$THEME_NAME" ]; then
THEMES_DIR="$HOME/.config/nomarchy/themes"
else
THEMES_DIR="$HOME/.local/share/nomarchy/themes"
fi
BG_DIR="$THEMES_DIR/$THEME_NAME/backgrounds"
if [ ! -d "$BG_DIR" ]; then
notify-send "No background directory found for theme $THEME_NAME"
exit 1
fi
mapfile -t BACKGROUNDS < <(ls "$BG_DIR" | sort)
TOTAL=${#BACKGROUNDS[@]}
if (( TOTAL == 0 )); then
notify-send "No backgrounds found in $BG_DIR"
exit 1
fi
CURRENT_BG=$(jq -r '.wallpaper' "$STATE_FILE")
INDEX=-1
for i in "${!BACKGROUNDS[@]}"; do
if [[ "$BG_DIR/${BACKGROUNDS[$i]}" == "$CURRENT_BG" ]]; then
INDEX=$i
break
fi
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"
# Instant feedback via swww
if pgrep -x swww-daemon >/dev/null; then
swww img "$NEW_BG" --transition-type outer --transition-pos 0.85,0.97 --transition-step 90
else
swww init && swww img "$NEW_BG"
fi
echo "Background set to $NEW_BG declaratively."

View File

@@ -0,0 +1,18 @@
#!/bin/bash
# Sets the specified image as the current background
if [[ -z $1 ]]; then
echo "Usage: nomarchy-theme-bg-set <path-to-image>" >&2
exit 1
fi
BACKGROUND="$1"
CURRENT_BACKGROUND_LINK="$HOME/.config/nomarchy/current/background"
# Create symlink to the new background
ln -nsf "$BACKGROUND" "$CURRENT_BACKGROUND_LINK"
# Kill existing swaybg and start new one
pkill -x swaybg
setsid uwsm-app -- swaybg -i "$CURRENT_BACKGROUND_LINK" -m fill >/dev/null 2>&1 &

View File

@@ -0,0 +1,9 @@
#!/bin/bash
THEME_NAME_PATH="$HOME/.config/nomarchy/current/theme.name"
if [[ -f $THEME_NAME_PATH ]]; then
cat $THEME_NAME_PATH | sed -E 's/(^|-)([a-z])/\1\u\2/g; s/-/ /g'
else
echo "Unknown"
fi

View File

@@ -0,0 +1,33 @@
#!/bin/bash
# nomarchy-theme-install: Install a new theme from a git repo for Nomarchy
# Usage: nomarchy-theme-install <git-repo-url>
if [[ -z $1 ]]; then
echo -e "\e[32mSee https://manuals.omamix.org/2/the-nomarchy-manual/90/extra-themes\n\e[0m"
REPO_URL=$(gum input --placeholder="Git repo URL for theme" --header="")
else
REPO_URL="$1"
fi
if [[ -z $REPO_URL ]]; then
exit 1
fi
THEMES_DIR="$HOME/.config/nomarchy/themes"
THEME_NAME=$(basename "$REPO_URL" .git | sed -E 's/^nomarchy-//; s/-theme$//')
THEME_PATH="$THEMES_DIR/$THEME_NAME"
# Remove existing theme if present
if [[ -d $THEME_PATH ]]; then
rm -rf "$THEME_PATH"
fi
# Clone the repo directly to ~/.config/nomarchy/themes
if ! git clone "$REPO_URL" "$THEME_PATH"; then
echo "Error: Failed to clone theme repo."
exit 1
fi
# Apply the new theme with nomarchy-theme-set
nomarchy-theme-set $THEME_NAME

View File

@@ -0,0 +1,8 @@
#!/bin/bash
{
find ~/.config/nomarchy/themes/ -mindepth 1 -maxdepth 1 \( -type d -o -type l \) -printf '%f\n'
find "$NOMARCHY_PATH/assets/themes/" -mindepth 1 -maxdepth 1 -type d -printf '%f\n'
} | sort -u | while read -r name; do
echo "$name" | sed -E 's/(^|-)([a-z])/\1\u\2/g; s/-/ /g'
done

View File

@@ -0,0 +1,9 @@
#!/bin/bash
# Refresh the current theme from its templates.
THEME_NAME_PATH="$HOME/.config/nomarchy/current/theme.name"
if [[ -f $THEME_NAME_PATH ]]; then
nomarchy-theme-set "$(cat $THEME_NAME_PATH)"
fi

View File

@@ -0,0 +1,35 @@
#!/bin/bash
# nomarchy-theme-remove: Remove a theme from Nomarchy by name
# Usage: nomarchy-theme-remove <theme-name>
if [[ -z $1 ]]; then
mapfile -t extra_themes < <(find ~/.config/nomarchy/themes -mindepth 1 -maxdepth 1 -type d ! -xtype l -printf '%f\n')
if (( ${#extra_themes[@]} > 0 )); then
THEME_NAME=$(printf '%s\n' "${extra_themes[@]}" | sort | gum choose --header="Remove extra theme")
else
echo "No extra themes installed."
exit 1
fi
else
THEME_NAME="$1"
fi
THEMES_DIR="$HOME/.config/nomarchy/themes"
CURRENT_DIR="$HOME/.config/nomarchy/current"
THEME_PATH="$THEMES_DIR/$THEME_NAME"
# Ensure a theme was set
if [[ -z $THEME_NAME ]]; then
exit 1
fi
# Check if theme exists before attempting removal
if [[ ! -d $THEME_PATH ]]; then
echo "Error: Theme '$THEME_NAME' not found."
exit 1
fi
# Now remove the theme directory for THEME_NAME
rm -rf "$THEME_PATH"

View File

@@ -0,0 +1,55 @@
#!/usr/bin/env bash
# Set the system theme declaratively.
# Usage: nomarchy-theme-set <theme-name>
THEME_NAME="$1"
if [[ -z $THEME_NAME ]]; then
echo "Usage: nomarchy-theme-set <theme-name>"
exit 1
fi
STATE_DIR="$HOME/.config/nomarchy"
STATE_FILE="$STATE_DIR/state.json"
# Resolve themes directory (Built-in from Nix store via Home Manager, or user extra)
if [ -d "$HOME/.config/nomarchy/themes/$THEME_NAME" ]; then
THEMES_DIR="$HOME/.config/nomarchy/themes"
else
THEMES_DIR="$HOME/.local/share/nomarchy/themes"
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"
fi
TMP_JSON=$(mktemp)
jq --arg theme "$THEME_NAME" '.theme = $theme' "$STATE_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$STATE_FILE"
# 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
sudo jq --arg theme "$THEME_NAME" '.theme = $theme' "$SYSTEM_STATE_FILE" > /tmp/system-state.json 2>/dev/null && sudo mv /tmp/system-state.json "$SYSTEM_STATE_FILE" 2>/dev/null || true
fi
# 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
TMP_JSON=$(mktemp)
jq --arg wp "$BG_DIR/$BG" '.wallpaper = $wp' "$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"

View File

@@ -0,0 +1,4 @@
#!/bin/bash
nomarchy-theme-set-keyboard-asus-rog
nomarchy-theme-set-keyboard-f16

View File

@@ -0,0 +1,7 @@
#!/bin/bash
ASUSCTL_THEME=~/.config/nomarchy/current/theme/keyboard.rgb
if nomarchy-cmd-present asusctl; then
asusctl aura effect static -c $(sed 's/^#//' $ASUSCTL_THEME)
fi

View File

@@ -0,0 +1,22 @@
#!/bin/bash
FRAMEWORK16_THEME=~/.config/nomarchy/current/theme/keyboard.rgb
if nomarchy-cmd-present qmk_hid && [[ -f $FRAMEWORK16_THEME ]]; then
hex=$(cat "$FRAMEWORK16_THEME")
hex="${hex#\#}"
# Convert hex to QMK HSV (0-255 scale) using Python's colorsys
read -r h s <<< $(python3 -c "
import colorsys
r, g, b = int('$hex'[:2],16)/255, int('$hex'[2:4],16)/255, int('$hex'[4:6],16)/255
h, s, v = colorsys.rgb_to_hsv(r, g, b)
print(int(h * 255), int(s * 255))
")
qmk_hid via --rgb-effect 1 2>/dev/null
qmk_hid via --rgb-hue "$h" 2>/dev/null
qmk_hid via --rgb-saturation "$s" 2>/dev/null
qmk_hid via --rgb-brightness 100 2>/dev/null
qmk_hid via --save 2>/dev/null
fi

View File

@@ -0,0 +1,27 @@
#!/bin/bash
# Sync Nomarchy theme to all Obsidian vaults
CURRENT_THEME_DIR="$HOME/.config/nomarchy/current/theme"
[[ -f $CURRENT_THEME_DIR/obsidian.css ]] || exit 0
jq -r '.vaults | values[].path' ~/.config/obsidian/obsidian.json 2>/dev/null | while read -r vault_path; do
[[ -d $vault_path/.obsidian ]] || continue
theme_dir="$vault_path/.obsidian/themes/Nomarchy"
mkdir -p "$theme_dir"
[[ -f $theme_dir/manifest.json ]] || cat >"$theme_dir/manifest.json" <<'EOF'
{
"name": "Nomarchy",
"version": "1.0.0",
"minAppVersion": "0.16.0",
"description": "Automatically syncs with your current Nomarchy system theme colors and fonts",
"author": "Nomarchy",
"authorUrl": "https://nomarchy.org"
}
EOF
cp "$CURRENT_THEME_DIR/obsidian.css" "$theme_dir/theme.css"
done

View File

@@ -0,0 +1,46 @@
#!/bin/bash
TEMPLATES_DIR="$NOMARCHY_PATH/assets/themed"
USER_TEMPLATES_DIR="$HOME/.config/nomarchy/themed"
NEXT_THEME_DIR="$HOME/.config/nomarchy/current/theme"
COLORS_FILE="$NEXT_THEME_DIR/colors.toml"
# Convert hex color to decimal RGB (e.g., "#1e1e2e" -> "30,30,46")
hex_to_rgb() {
local hex="${1#\#}"
printf "%d,%d,%d" "0x${hex:0:2}" "0x${hex:2:2}" "0x${hex:4:2}"
}
# Only generate dynamic templates for themes with a colors.toml definition
if [[ -f $COLORS_FILE ]]; then
sed_script=$(mktemp)
while IFS='=' read -r key value; do
key="${key//[\"\' ]/}" # strip quotes and spaces from key
[[ $key && $key != \#* ]] || continue # skip empty lines and comments
value="${value#*[\"\']}"
value="${value%%[\"\']*}" # extract value between quotes (ignores inline comments)
printf 's|{{ %s }}|%s|g\n' "$key" "$value" # {{ key }} -> value
printf 's|{{ %s_strip }}|%s|g\n' "$key" "${value#\#}" # {{ key_strip }} -> value without leading #
if [[ $value =~ ^# ]]; then
rgb=$(hex_to_rgb "$value")
echo "s|{{ ${key}_rgb }}|${rgb}|g"
fi
done <"$COLORS_FILE" >"$sed_script"
shopt -s nullglob
# Process user templates first, then built-in templates (user overrides built-in)
for tpl in "$USER_TEMPLATES_DIR"/*.tpl "$TEMPLATES_DIR"/*.tpl; do
filename=$(basename "$tpl" .tpl)
output_path="$NEXT_THEME_DIR/$filename"
# Don't overwrite configs already exists in the output directory (copied from theme specific folder)
if [[ ! -f $output_path ]]; then
sed -f "$sed_script" "$tpl" >"$output_path"
fi
done
rm "$sed_script"
fi

View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# Nomarchy VS Code Theme Setter
# This script only updates the global state.json.
# Home Manager (modules/home/vscode.nix) handles the declarative settings injection.
STATE_DIR="$HOME/.config/nomarchy"
STATE_FILE="$STATE_DIR/state.json"
mkdir -p "$STATE_DIR"
[[ ! -f $STATE_FILE ]] && echo "{}" > "$STATE_FILE"
# Theme is already set in state.json by nomarchy-theme-set.
# This script is now mostly a placeholder to maintain the same workflow,
# triggering an env-update if needed to apply the declarative changes.
if [[ $NOMARCHY_TOGGLE_SKIP_VSCODE_THEME != "true" ]]; then
# We trigger env-update to apply the new VSCode theme declaratively.
env-update
fi

View File

@@ -0,0 +1,8 @@
#!/bin/bash
for dir in ~/.config/nomarchy/themes/*/; do
if [[ -d $dir ]] && [[ ! -L ${dir%/} ]] && [[ -d $dir/.git ]]; then
echo "Updating: $(basename "$dir")"
git -C "$dir" pull
fi
done

View File

@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Toggles the nightlight (hyprsunset).
# Hybrid: updates state.json and provides instant feedback.
STATE_DIR="$HOME/.config/nomarchy"
STATE_FILE="$STATE_DIR/state.json"
mkdir -p "$STATE_DIR"
# Initialize if doesn't exist
[[ ! -f $STATE_FILE ]] && echo "{}" > "$STATE_FILE"
if [[ $NOMARCHY_TOGGLE_NIGHTLIGHT == "false" ]]; then
NEW_VALUE="true"
hyprctl dispatch exec hyprsunset --temperature 4000
notify-send -u low " Nightlight enabled"
else
NEW_VALUE="false"
pkill hyprsunset
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"
echo "Nightlight state set to $NEW_VALUE. Environment will be fully updated on next rebuild."