From 9746e75bc543ee7fc2e4d39d3f153bbbacf84d74 Mon Sep 17 00:00:00 2001 From: Bernardo Magri Date: Mon, 13 Apr 2026 13:25:54 +0100 Subject: [PATCH] fix: dynamic flake path resolution and replace env-update/sys-update aliases with scripts --- core/system/scripts/nomarchy-pkg-add | 4 ++-- core/system/scripts/nomarchy-pkg-remove | 4 ++-- core/system/scripts/nomarchy-setup-dns | 2 +- core/system/scripts/nomarchy-setup-fido2 | 4 ++-- core/system/scripts/nomarchy-setup-fingerprint | 4 ++-- core/system/scripts/nomarchy-toggle-hybrid-gpu | 2 +- core/system/scripts/nomarchy-toggle-suspend | 4 ++-- core/system/scripts/nomarchy-tz-select | 2 +- core/system/scripts/nomarchy-update | 15 +++++++++------ core/system/scripts/nomarchy-wifi-powersave | 2 +- .../desktop/scripts/nomarchy-toggle-screensaver | 2 +- features/scripts/utils/nomarchy-env-update | 14 ++++++++++++-- features/scripts/utils/nomarchy-sys-update | 14 ++++++++++++-- features/scripts/utils/nomarchy-welcome | 2 +- themes/engine/scripts/nomarchy-font-set | 2 +- themes/engine/scripts/nomarchy-theme-set | 4 ++-- themes/engine/scripts/nomarchy-theme-set-vscode | 4 ++-- themes/engine/switcher.nix | 4 ++-- 18 files changed, 56 insertions(+), 33 deletions(-) diff --git a/core/system/scripts/nomarchy-pkg-add b/core/system/scripts/nomarchy-pkg-add index 9273b17..7c3014c 100755 --- a/core/system/scripts/nomarchy-pkg-add +++ b/core/system/scripts/nomarchy-pkg-add @@ -23,5 +23,5 @@ fi jq --arg pkg "$PKG_NAME" '. + [$pkg]' "$STATE_FILE" > "${STATE_FILE}.tmp" && mv "${STATE_FILE}.tmp" "$STATE_FILE" echo "Package $PKG_NAME added declaratively to $STATE_FILE." -echo "Applying changes with env-update..." -env-update +echo "Applying changes with nomarchy-env-update..." +nomarchy-env-update diff --git a/core/system/scripts/nomarchy-pkg-remove b/core/system/scripts/nomarchy-pkg-remove index b6de996..b5fde39 100755 --- a/core/system/scripts/nomarchy-pkg-remove +++ b/core/system/scripts/nomarchy-pkg-remove @@ -23,5 +23,5 @@ fi jq --arg pkg "$PKG_NAME" '. - [$pkg]' "$STATE_FILE" > "${STATE_FILE}.tmp" && mv "${STATE_FILE}.tmp" "$STATE_FILE" echo "Package $PKG_NAME removed declaratively from $STATE_FILE." -echo "Applying changes with env-update..." -env-update +echo "Applying changes with nomarchy-env-update..." +nomarchy-env-update diff --git a/core/system/scripts/nomarchy-setup-dns b/core/system/scripts/nomarchy-setup-dns index 61809d4..b79fd3c 100755 --- a/core/system/scripts/nomarchy-setup-dns +++ b/core/system/scripts/nomarchy-setup-dns @@ -32,4 +32,4 @@ Custom) esac echo "DNS configured to $dns. Applying changes..." -sudo sys-update +sudo nomarchy-sys-update diff --git a/core/system/scripts/nomarchy-setup-fido2 b/core/system/scripts/nomarchy-setup-fido2 index a07421b..5975925 100755 --- a/core/system/scripts/nomarchy-setup-fido2 +++ b/core/system/scripts/nomarchy-setup-fido2 @@ -7,13 +7,13 @@ STATE_FILE="/etc/nixos/state.json" if [[ "--remove" == $1 ]]; then sudo jq '.features.fido2 = false' "$STATE_FILE" > /tmp/state.json && sudo mv /tmp/state.json "$STATE_FILE" echo "FIDO2 support disabled. Applying changes..." - sudo sys-update + sudo nomarchy-sys-update exit 0 fi sudo jq '.features.fido2 = true' "$STATE_FILE" > /tmp/state.json && sudo mv /tmp/state.json "$STATE_FILE" echo "FIDO2 support enabled. Applying changes..." -sudo sys-update +sudo nomarchy-sys-update # Enrollment is still an imperative action if command -v pamu2fcfg &> /dev/null; then diff --git a/core/system/scripts/nomarchy-setup-fingerprint b/core/system/scripts/nomarchy-setup-fingerprint index d5a2842..37cce43 100755 --- a/core/system/scripts/nomarchy-setup-fingerprint +++ b/core/system/scripts/nomarchy-setup-fingerprint @@ -7,13 +7,13 @@ STATE_FILE="/etc/nixos/state.json" if [[ "--remove" == $1 ]]; then sudo jq '.features.fingerprint = false' "$STATE_FILE" > /tmp/state.json && sudo mv /tmp/state.json "$STATE_FILE" echo "Fingerprint support disabled. Applying changes..." - sudo sys-update + sudo nomarchy-sys-update exit 0 fi sudo jq '.features.fingerprint = true' "$STATE_FILE" > /tmp/state.json && sudo mv /tmp/state.json "$STATE_FILE" echo "Fingerprint support enabled. Applying changes..." -sudo sys-update +sudo nomarchy-sys-update # Enrollment is still an imperative action if command -v fprintd-enroll &> /dev/null; then diff --git a/core/system/scripts/nomarchy-toggle-hybrid-gpu b/core/system/scripts/nomarchy-toggle-hybrid-gpu index 53c7311..e042e73 100755 --- a/core/system/scripts/nomarchy-toggle-hybrid-gpu +++ b/core/system/scripts/nomarchy-toggle-hybrid-gpu @@ -10,7 +10,7 @@ if [[ $(sudo jq -r '.features.hybridGPU // false' "$STATE_FILE") != "true" ]]; t if gum confirm "Hybrid GPU support is not enabled. Enable it now? (Requires sys-update)"; then sudo jq '.features.hybridGPU = true' "$STATE_FILE" > /tmp/state.json && sudo mv /tmp/state.json "$STATE_FILE" echo "Hybrid GPU support enabled in configuration. Applying changes..." - sudo sys-update + sudo nomarchy-sys-update echo "Please run this command again after the update." exit 0 fi diff --git a/core/system/scripts/nomarchy-toggle-suspend b/core/system/scripts/nomarchy-toggle-suspend index 3d668ac..263da5a 100755 --- a/core/system/scripts/nomarchy-toggle-suspend +++ b/core/system/scripts/nomarchy-toggle-suspend @@ -25,5 +25,5 @@ jq --argjson val "$NEW_VALUE" '.suspend = $val' "$STATE_FILE" > "$TMP_JSON" && m echo "Suspend availability set to $NEW_VALUE. Updating environment..." -# Run env-update to apply changes to the menu -env-update +# Run nomarchy-env-update to apply changes to the menu +nomarchy-env-update diff --git a/core/system/scripts/nomarchy-tz-select b/core/system/scripts/nomarchy-tz-select index 89a33dd..e59bb30 100755 --- a/core/system/scripts/nomarchy-tz-select +++ b/core/system/scripts/nomarchy-tz-select @@ -9,4 +9,4 @@ timezone=$(timedatectl list-timezones | gum filter --height 20 --header "Set tim sudo jq --arg tz "$timezone" '.timezone = $tz' "$STATE_FILE" > /tmp/state.json && sudo mv /tmp/state.json "$STATE_FILE" echo "Timezone is now set to $timezone. Applying changes..." -sudo sys-update +sudo nomarchy-sys-update diff --git a/core/system/scripts/nomarchy-update b/core/system/scripts/nomarchy-update index 5fd6074..b4bebaf 100755 --- a/core/system/scripts/nomarchy-update +++ b/core/system/scripts/nomarchy-update @@ -1,20 +1,23 @@ #!/usr/bin/env bash # Nomarchy Update Script -# 1. Updates the flake inputs in /etc/nixos +# 1. Updates the flake inputs in the repository # 2. Applies system-wide NixOS changes # 3. Applies user-level Home Manager changes set -e -REPO_DIR="/etc/nixos" - -if [ ! -d "$REPO_DIR" ]; then - echo "Error: $REPO_DIR not found. Are you running on a Nomarchy system?" +# Detect the repository location +if [ -f "/etc/nixos/flake.nix" ]; then + REPO_DIR="/etc/nixos" +elif [ -f "/etc/nomarchy/flake.nix" ]; then + REPO_DIR="/etc/nomarchy" +else + echo "Error: Nomarchy flake repository not found in /etc/nixos or /etc/nomarchy." exit 1 fi -echo "--- Starting Nomarchy Update ---" +echo "--- Starting Nomarchy Update from $REPO_DIR ---" # 1. Update Flake Lock echo "Updating flake inputs..." diff --git a/core/system/scripts/nomarchy-wifi-powersave b/core/system/scripts/nomarchy-wifi-powersave index 059580a..bf51616 100755 --- a/core/system/scripts/nomarchy-wifi-powersave +++ b/core/system/scripts/nomarchy-wifi-powersave @@ -14,4 +14,4 @@ esac sudo jq --argjson val "$value" '.wifi.powersave = $val' "$STATE_FILE" > /tmp/state.json && sudo mv /tmp/state.json "$STATE_FILE" echo "Wifi powersave set to $1. Applying changes..." -sudo sys-update +sudo nomarchy-sys-update diff --git a/features/desktop/scripts/nomarchy-toggle-screensaver b/features/desktop/scripts/nomarchy-toggle-screensaver index 0d34de3..6d23d61 100755 --- a/features/desktop/scripts/nomarchy-toggle-screensaver +++ b/features/desktop/scripts/nomarchy-toggle-screensaver @@ -23,4 +23,4 @@ jq --argjson val "$NEW_VALUE" '.screensaver = $val' "$STATE_FILE" > "$TMP_JSON" echo "Screensaver state set to $NEW_VALUE. Updating environment..." -env-update +nomarchy-env-update diff --git a/features/scripts/utils/nomarchy-env-update b/features/scripts/utils/nomarchy-env-update index 1208e3a..862e06d 100644 --- a/features/scripts/utils/nomarchy-env-update +++ b/features/scripts/utils/nomarchy-env-update @@ -6,13 +6,23 @@ set -e +# Detect the repository location +if [ -f "/etc/nixos/flake.nix" ]; then + REPO_DIR="/etc/nixos" +elif [ -f "/etc/nomarchy/flake.nix" ]; then + REPO_DIR="/etc/nomarchy" +else + echo "Error: Nomarchy flake repository not found in /etc/nixos or /etc/nomarchy." + exit 1 +fi + # Use the pre-flight migration script to ensure the state is synced before evaluation if command -v nomarchy-preflight-migration >/dev/null 2>&1; then nomarchy-preflight-migration fi # Apply Home Manager changes from the local flake -echo "Applying user-level changes..." -home-manager switch --flake /etc/nixos#default --impure +echo "Applying user-level changes from $REPO_DIR..." +home-manager switch --flake "$REPO_DIR#default" --impure echo "Environment update complete." diff --git a/features/scripts/utils/nomarchy-sys-update b/features/scripts/utils/nomarchy-sys-update index 38d033e..cdbe83a 100644 --- a/features/scripts/utils/nomarchy-sys-update +++ b/features/scripts/utils/nomarchy-sys-update @@ -5,8 +5,18 @@ set -e +# Detect the repository location +if [ -f "/etc/nixos/flake.nix" ]; then + REPO_DIR="/etc/nixos" +elif [ -f "/etc/nomarchy/flake.nix" ]; then + REPO_DIR="/etc/nomarchy" +else + echo "Error: Nomarchy flake repository not found in /etc/nixos or /etc/nomarchy." + exit 1 +fi + # Apply NixOS changes from the local flake -echo "Applying system-level changes..." -sudo nixos-rebuild switch --flake /etc/nixos#default --impure +echo "Applying system-level changes from $REPO_DIR..." +sudo nixos-rebuild switch --flake "$REPO_DIR#default" --impure echo "System update complete." diff --git a/features/scripts/utils/nomarchy-welcome b/features/scripts/utils/nomarchy-welcome index 1b02a39..e4d4097 100755 --- a/features/scripts/utils/nomarchy-welcome +++ b/features/scripts/utils/nomarchy-welcome @@ -29,7 +29,7 @@ nomarchy-theme-set "$(nomarchy-theme-list | gum filter --placeholder 'Select a t echo "Step 2: Choose your preferred font" nomarchy-font-set "$(nomarchy-font-list | gum filter --placeholder 'Select a font...')" -# 3. Setup Local Repo (Crucial for env-update to work) +# 3. Setup Local Repo (Crucial for nomarchy-env-update to work) echo "" echo "Nomarchy relies on a local git repository for declarative updates." if [ ! -d "/etc/nixos/.git" ]; then diff --git a/themes/engine/scripts/nomarchy-font-set b/themes/engine/scripts/nomarchy-font-set index b00964d..e1f6086 100755 --- a/themes/engine/scripts/nomarchy-font-set +++ b/themes/engine/scripts/nomarchy-font-set @@ -20,7 +20,7 @@ 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 + nomarchy-env-update # Instant feedback for certain apps via IPC if pgrep -x kitty; then diff --git a/themes/engine/scripts/nomarchy-theme-set b/themes/engine/scripts/nomarchy-theme-set index 2fbbed9..21d94f8 100755 --- a/themes/engine/scripts/nomarchy-theme-set +++ b/themes/engine/scripts/nomarchy-theme-set @@ -46,8 +46,8 @@ if [ -d "$BG_DIR" ]; then fi fi -echo "Theme set to $THEME_NAME. Applying changes with env-update..." -env-update +echo "Theme set to $THEME_NAME. Applying changes with nomarchy-env-update..." +nomarchy-env-update nomarchy-theme-set-templates diff --git a/themes/engine/scripts/nomarchy-theme-set-vscode b/themes/engine/scripts/nomarchy-theme-set-vscode index bb38b63..d0c061e 100755 --- a/themes/engine/scripts/nomarchy-theme-set-vscode +++ b/themes/engine/scripts/nomarchy-theme-set-vscode @@ -15,6 +15,6 @@ mkdir -p "$STATE_DIR" # 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 + # We trigger nomarchy-env-update to apply the new VSCode theme declaratively. + nomarchy-env-update fi diff --git a/themes/engine/switcher.nix b/themes/engine/switcher.nix index 6deb829..2b4cda5 100644 --- a/themes/engine/switcher.nix +++ b/themes/engine/switcher.nix @@ -26,7 +26,7 @@ let if [ -n "$SELECTED_FONT" ]; then TMP_JSON=$(mktemp) jq --arg font "$SELECTED_FONT" '.font = $font' "$STATE_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$STATE_FILE" - env-update + nomarchy-env-update fi ''; @@ -55,7 +55,7 @@ let TMP_JSON=$(mktemp) jq --arg wp "$SELECTED_WP" '.wallpaper = $wp' "$STATE_FILE" > "$TMP_JSON" && mv "$TMP_JSON" "$STATE_FILE" swww img "$SELECTED_WP" --transition-type outer --transition-pos 0.85,0.97 --transition-step 90 & - env-update + nomarchy-env-update fi ''; in