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
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() {
local cmd="$1"
shift
local GUM_CMD
local gum_exec
if command -v gum >/dev/null 2>&1; then
GUM_CMD="gum"
gum_exec=(command gum)
else
# 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
case "$cmd" in
input|confirm|choose|filter|write)
$GUM_CMD "$cmd" "$@" < /dev/tty
"${gum_exec[@]}" "$cmd" "$@" < /dev/tty
;;
*)
$GUM_CMD "$cmd" "$@"
"${gum_exec[@]}" "$cmd" "$@"
;;
esac
}
clear
# --- TITLE SCREEN ---
gum style \
--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"
echo "This script will generate your private downstream environment."
gum format "This protocol will bootstrap your **private downstream** environment."
echo ""
# 1. Gather User Information
USERNAME=$(gum input --placeholder "Enter your Linux username")
HOSTNAME=$(gum input --placeholder "Enter a hostname for this machine (e.g., nomarchy-sys)")
# --- STEP 1: USER INPUT ---
gum style --foreground 212 "👤 User Configuration"
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"
echo "Creating local downstream repository at $LOCAL_DIR..."
mkdir -p "$LOCAL_DIR"/{system,home,secrets}
# 3. Harvest the Hardware Configuration
# A barebones install leaves this in /etc/nixos. We need it.
echo "Copying hardware configuration..."
gum format "### ⚙️ Initializing Architecture"
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 chown "$USER:users" "$LOCAL_DIR/system/hardware-configuration.nix"
gum style --foreground 120 " ✔ Imported hardware-configuration.nix"
# 4. Generate the Downstream Flake
echo "Drafting your private flake.nix..."
# --- STEP 3: FLAKE GENERATION ---
cat <<EOF > "$LOCAL_DIR/flake.nix"
{
description = "Private Downstream Machine Config (Nomarchy)";
@@ -93,7 +107,6 @@ cat <<EOF > "$LOCAL_DIR/flake.nix"
}
EOF
# 5. Generate the Scaffolding Files
cat <<EOF > "$LOCAL_DIR/system/configuration.nix"
{ pkgs, ... }: {
networking.hostName = "$HOSTNAME";
@@ -116,32 +129,44 @@ cat <<EOF > "$LOCAL_DIR/home/home.nix"
}
EOF
# 6. Initialize Version Control
echo "Initializing Git repository..."
nix run nixpkgs#git -- -C "$LOCAL_DIR" init
nix run nixpkgs#git -- -C "$LOCAL_DIR" add .
gum style --foreground 120 " ✔ Generated unified flake.nix and sub-modules"
# 7. Execution
clear
# --- STEP 4: VERSION CONTROL ---
# 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 \
--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"
echo "Your private downstream configuration has been generated."
if gum confirm "Build Nomarchy OS now? (This will take a few minutes)"; then
echo "Building System Engine..."
if gum confirm "Build Nomarchy OS now?"; then
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"
echo "Building User Interface..."
gum spin --spinner line --title " Building User Interface..." -- \
nix run home-manager/release-25.11 -- switch --flake "$LOCAL_DIR#$USERNAME"
clear
gum style \
--foreground 212 --border-foreground 212 --border double \
--align center --width 50 --margin "1 2" --padding "2 4" \
"Installation Complete"
echo "Welcome to Nomarchy OS. Reboot to enter your new environment."
--foreground 120 --border-foreground 120 --border double \
--align center --width 60 --margin "1 2" --padding "2 4" \
"Installation Complete" \
"Welcome to Nomarchy OS."
gum format "Reboot your machine to enter the new environment."
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