fixing install.sh

This commit is contained in:
Bernardo Magri
2026-04-10 20:25:58 +01:00
parent 7590fc4057
commit 9f62f0f5f1

View File

@@ -1,54 +1,68 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
# Define a wrapper for gum to handle Nix run fallback and TTY redirection # Ensure flakes are enabled for the script's execution environment
export NIX_CONFIG="experimental-features = nix-command flakes"
# Define a safe wrapper for gum using arrays to prevent word-splitting bugs
gum() { gum() {
local cmd="$1" local cmd="$1"
shift shift
local GUM_CMD local gum_exec
if command -v gum >/dev/null 2>&1; then if command -v gum >/dev/null 2>&1; then
GUM_CMD="gum" gum_exec=(command gum)
else else
# Use --quiet to avoid progress bars in captured output # Use --quiet to avoid progress bars in captured output
GUM_CMD="nix run --quiet --extra-experimental-features nix-command --extra-experimental-features flakes nixpkgs#gum --" gum_exec=(nix run --quiet nixpkgs#gum --)
fi fi
case "$cmd" in case "$cmd" in
input|confirm|choose|filter|write) input|confirm|choose|filter|write)
$GUM_CMD "$cmd" "$@" < /dev/tty "${gum_exec[@]}" "$cmd" "$@" < /dev/tty
;; ;;
*) *)
$GUM_CMD "$cmd" "$@" "${gum_exec[@]}" "$cmd" "$@"
;; ;;
esac esac
} }
clear clear
# --- TITLE SCREEN ---
gum style \ gum style \
--foreground 212 --border-foreground 212 --border double \ --foreground 212 --border-foreground 212 --border double \
--align center --width 50 --margin "1 2" --padding "2 4" \ --align center --width 60 --margin "1 2" --padding "2 4" \
"NOMARCHY" "The Omarchy-flavored NixOS" "NOMARCHY" "The Omarchy-flavored NixOS"
echo "This script will generate your private downstream environment." gum format "This protocol will bootstrap your **private downstream** environment."
echo "" echo ""
# 1. Gather User Information # --- STEP 1: USER INPUT ---
USERNAME=$(gum input --placeholder "Enter your Linux username") gum style --foreground 212 "👤 User Configuration"
HOSTNAME=$(gum input --placeholder "Enter a hostname for this machine (e.g., nomarchy-sys)") USERNAME=$(gum input --prompt " Username: " --placeholder "e.g., alan")
HOSTNAME=$(gum input --prompt " Hostname: " --placeholder "e.g., nomarchy-sys")
# 2. Setup the Local Directory echo ""
gum format "> **Target Directory:** \`$HOME/.nomarchy\`"
gum format "> **System User:** \`$USERNAME\`"
gum format "> **System Host:** \`$HOSTNAME\`"
echo ""
# --- STEP 2: DIRECTORY & HARDWARE SCAFFOLDING ---
LOCAL_DIR="$HOME/.nomarchy" LOCAL_DIR="$HOME/.nomarchy"
echo "Creating local downstream repository at $LOCAL_DIR..."
mkdir -p "$LOCAL_DIR"/{system,home,secrets}
# 3. Harvest the Hardware Configuration gum format "### ⚙️ Initializing Architecture"
# A barebones install leaves this in /etc/nixos. We need it.
echo "Copying hardware configuration..." mkdir -p "$LOCAL_DIR"/{system,home,secrets}
gum style --foreground 120 " ✔ Created local repository structure"
# Harvest the Hardware Configuration
sudo cp /etc/nixos/hardware-configuration.nix "$LOCAL_DIR/system/" sudo cp /etc/nixos/hardware-configuration.nix "$LOCAL_DIR/system/"
sudo chown "$USER:users" "$LOCAL_DIR/system/hardware-configuration.nix" sudo chown "$USER:users" "$LOCAL_DIR/system/hardware-configuration.nix"
gum style --foreground 120 " ✔ Imported hardware-configuration.nix"
# 4. Generate the Downstream Flake # --- STEP 3: FLAKE GENERATION ---
echo "Drafting your private flake.nix..."
cat <<EOF > "$LOCAL_DIR/flake.nix" cat <<EOF > "$LOCAL_DIR/flake.nix"
{ {
description = "Private Downstream Machine Config (Nomarchy)"; description = "Private Downstream Machine Config (Nomarchy)";
@@ -93,7 +107,6 @@ cat <<EOF > "$LOCAL_DIR/flake.nix"
} }
EOF EOF
# 5. Generate the Scaffolding Files
cat <<EOF > "$LOCAL_DIR/system/configuration.nix" cat <<EOF > "$LOCAL_DIR/system/configuration.nix"
{ pkgs, ... }: { { pkgs, ... }: {
networking.hostName = "$HOSTNAME"; networking.hostName = "$HOSTNAME";
@@ -116,32 +129,44 @@ cat <<EOF > "$LOCAL_DIR/home/home.nix"
} }
EOF EOF
# 6. Initialize Version Control gum style --foreground 120 " ✔ Generated unified flake.nix and sub-modules"
echo "Initializing Git repository..."
nix run nixpkgs#git -- -C "$LOCAL_DIR" init
nix run nixpkgs#git -- -C "$LOCAL_DIR" add .
# 7. Execution # --- STEP 4: VERSION CONTROL ---
clear # Wrapped in a spinner for a cleaner look
gum spin --spinner dot --title " Initializing Version Control..." -- bash -c "
nix run nixpkgs#git -- -C \"$LOCAL_DIR\" init > /dev/null 2>&1
nix run nixpkgs#git -- -C \"$LOCAL_DIR\" add . > /dev/null 2>&1
"
gum style --foreground 120 " ✔ Version control active"
echo ""
# --- STEP 5: EXECUTION GATE ---
gum style \ gum style \
--foreground 212 --border-foreground 212 --border normal \ --foreground 212 --border-foreground 212 --border normal \
--align center --width 50 --margin "1 2" --padding "1 2" \ --align center --width 60 --margin "1 2" --padding "1 2" \
"Ready for Genesis" "Ready for Genesis"
echo "Your private downstream configuration has been generated."
if gum confirm "Build Nomarchy OS now? (This will take a few minutes)"; then if gum confirm "Build Nomarchy OS now?"; then
echo "Building System Engine..." echo ""
# Run builds with a spinner to hide the massive text dump
gum spin --spinner line --title " Compiling System Engine (Requires Sudo)..." -- \
sudo nixos-rebuild switch --flake "$LOCAL_DIR#$HOSTNAME" --extra-experimental-features "nix-command flakes" sudo nixos-rebuild switch --flake "$LOCAL_DIR#$HOSTNAME" --extra-experimental-features "nix-command flakes"
echo "Building User Interface..." gum spin --spinner line --title " Building User Interface..." -- \
nix run home-manager/release-25.11 -- switch --flake "$LOCAL_DIR#$USERNAME" nix run home-manager/release-25.11 -- switch --flake "$LOCAL_DIR#$USERNAME"
clear clear
gum style \ gum style \
--foreground 212 --border-foreground 212 --border double \ --foreground 120 --border-foreground 120 --border double \
--align center --width 50 --margin "1 2" --padding "2 4" \ --align center --width 60 --margin "1 2" --padding "2 4" \
"Installation Complete" "Installation Complete" \
echo "Welcome to Nomarchy OS. Reboot to enter your new environment." "Welcome to Nomarchy OS."
gum format "Reboot your machine to enter the new environment."
else else
echo "Aborted. You can review your files in $LOCAL_DIR and run the build manually later." echo ""
gum style --foreground 196 "Deployment aborted."
gum format "Your configuration files are safely stored in \`$LOCAL_DIR\`."
gum format "You can inspect them and run the build manually later."
fi fi