#!/usr/bin/env bash set -e # Nomarchy Nix State Sync # Bridges the gap between runtime UI changes (state.json) and declarative # Nix configuration (nomarchy-state.nix). STATE_JSON="$HOME/.config/nomarchy/state.json" NIX_STATE_FILE="/etc/nixos/nomarchy-state.nix" # If state.json is missing, nothing to sync if [ ! -f "$STATE_JSON" ]; then exit 0 fi # Determine destination. # If we are in the repo, we sync to ./nomarchy-state.nix (dev mode). # Otherwise, we sync to /etc/nixos/nomarchy-state.nix (real install). if [ -f "flake.nix" ] || [ -d ".git" ]; then DEST="./nomarchy-state.nix" elif [ -w "/etc/nixos" ]; then DEST="$NIX_STATE_FILE" else # Nowhere to sync to exit 0 fi # Generate the Nix attribute set from JSON. # We use jq to extract the keys and format them as Nix assignments. # Note: font in state.json maps to fonts.monospace in Nix. { echo "# DO NOT EDIT MANUALLY - Managed by Nomarchy scripts." echo "# This file mirrors your UI choices (theme, font, etc.) into the declarative" echo "# Nix configuration. It is imported by your home.nix." echo "{ lib, ... }:" echo "{" echo " nomarchy = {" # Core UI strings echo " theme = lib.mkDefault \"$(jq -r '.theme // empty' "$STATE_JSON")\";" echo " fonts.monospace = lib.mkDefault \"$(jq -r '.font // empty' "$STATE_JSON")\";" echo " panelPosition = lib.mkDefault \"$(jq -r '.panelPosition // empty' "$STATE_JSON")\";" echo " wallpaper = lib.mkDefault \"$(jq -r '.wallpaper // empty' "$STATE_JSON")\";" # Hyprland layout (numbers) echo " hyprland = {" echo " scale = lib.mkDefault \"$(jq -r '.hyprland.scale // "auto"' "$STATE_JSON")\";" echo " gaps_in = lib.mkDefault $(jq -r '.hyprland.gaps_in // 5' "$STATE_JSON");" echo " gaps_out = lib.mkDefault $(jq -r '.hyprland.gaps_out // 10' "$STATE_JSON");" echo " border_size = lib.mkDefault $(jq -r '.hyprland.border_size // 2' "$STATE_JSON");" echo " };" # Toggles (booleans) echo " toggles = {" echo " suspend = lib.mkDefault $(jq -r '.suspend // true' "$STATE_JSON");" echo " screensaver = lib.mkDefault $(jq -r '.screensaver // true' "$STATE_JSON");" echo " idle = lib.mkDefault $(jq -r '.idle // true' "$STATE_JSON");" echo " nightlight = lib.mkDefault $(jq -r '.nightlight // false' "$STATE_JSON");" echo " waybar = lib.mkDefault $(jq -r '.waybar // true' "$STATE_JSON");" echo " };" echo " };" echo "}" } > "$DEST.tmp" # Final atomic move mv "$DEST.tmp" "$DEST"