11#! /bin/bash
2- set -e
2+ set -ex
33
44echo " === Antigravity Nix Feature ==="
55
6- # --- 1. Install essential packages ---
6+ # --- 1. Install essential packages (Minus Direnv) ---
77echo " Installing essential packages..."
88apt-get update
99apt-get install -y --no-install-recommends \
@@ -15,7 +15,6 @@ apt-get install -y --no-install-recommends \
1515 xz-utils \
1616 gnupg \
1717 procps \
18- direnv \
1918 pass
2019rm -rf /var/lib/apt/lists/*
2120
@@ -35,7 +34,10 @@ chown 1000:1000 /nix
3534
3635# --- 4. Install Nix (single-user mode as vscode) ---
3736echo " Installing Nix..."
38- su - vscode -c ' curl -L https://nixos.org/nix/install | sh -s -- --no-daemon'
37+ if [ ! -d /home/vscode/.nix-profile ]; then
38+ # We use the official installer, ensure it works non-interactively
39+ su - vscode -c ' curl -L https://nixos.org/nix/install | sh -s -- --no-daemon'
40+ fi
3941
4042# --- 5. Configure Nix for flakes ---
4143echo " Configuring Nix for flakes..."
@@ -45,19 +47,76 @@ experimental-features = nix-command flakes
4547build-users-group =
4648EOF
4749
48- # --- 6. Add Nix to profile for all shells ---
50+ # --- 6. Add Nix to profile for all shells (Zero-Prompt Ready) ---
4951echo " Adding Nix to shell profile..."
52+ rm -f /etc/profile.d/nix.sh
5053cat >> /etc/profile.d/nix.sh << 'EOF '
5154if [ -e '/home/vscode/.nix-profile/etc/profile.d/nix.sh' ]; then
5255 . '/home/vscode/.nix-profile/etc/profile.d/nix.sh'
5356fi
5457EOF
5558
56- cat >> /etc/bash.bashrc << 'EOF '
57- if [ -e '/home/vscode/.nix-profile/etc/profile.d/nix.sh' ]; then
58- . '/home/vscode/.nix-profile/etc/profile.d/nix.sh'
59+ # --- 7. Create global antigravity-setup-env command ---
60+ echo " Creating antigravity-setup-env command..."
61+ cat << 'SETUPEOF ' > /usr/local/bin/antigravity-setup-env
62+ #!/bin/bash
63+ set -ex
64+
65+ # Establish safe directory
66+ git config --global --add safe.directory '*'
67+
68+ # 1. Locate and Source Nix (Crucial for nix print-dev-env)
69+ NIX_PATHS=(
70+ "/home/vscode/.nix-profile/etc/profile.d/nix.sh"
71+ "/nix/var/nix/profiles/default/etc/profile.d/nix.sh"
72+ "/etc/profile.d/nix.sh"
73+ )
74+
75+ for profile in "${NIX_PATHS[@]}"; do
76+ if [ -f "$profile" ]; then
77+ echo "Sourcing Nix from $profile"
78+ . "$profile"
79+ break
80+ fi
81+ done
82+
83+ # Ensure nix is on PATH even if sourcing failed to be perfect
84+ export PATH="/home/vscode/.nix-profile/bin:/nix/var/nix/profiles/default/bin:$PATH"
85+
86+ # 2. Generate Nix environment cache
87+ # Default to /infra/foundation if WORKSPACE_FOLDER not set
88+ TARGET_DIR="${WORKSPACE_FOLDER:-/infra/foundation}"
89+ echo "Generating Nix environment cache in $TARGET_DIR..."
90+
91+ if [ -f "$TARGET_DIR/flake.nix" ]; then
92+ nix print-dev-env --impure "$TARGET_DIR" > "$TARGET_DIR/.env"
93+ echo "> environment cache generated successfully"
94+ else
95+ echo "WARNING: No flake.nix found in $TARGET_DIR. Nix env not cached."
96+ fi
97+
98+ echo "Setup complete!"
99+ SETUPEOF
100+ chmod +x /usr/local/bin/antigravity-setup-env
101+
102+ # --- 8. Pre-configure vscode user's .bashrc ---
103+ echo " Configuring vscode user's .bashrc for Zero-Prompt..."
104+ BASHRC=" /home/vscode/.bashrc"
105+ # Create if doesn't exist (though it should)
106+ touch " $BASHRC "
107+ chown 1000:1000 " $BASHRC "
108+
109+ if ! grep -q " Zero-Prompt Nix Activation" " $BASHRC " ; then
110+ cat << 'BASHEOF ' >> "$BASHRC"
111+
112+ # === Zero-Prompt Nix Activation ===
113+ if [ -f "/infra/foundation/.env" ]; then
114+ . "/infra/foundation/.env"
115+ # Re-initialize starship if present in the nix env
116+ command -v starship >/dev/null && eval "$(starship init bash)"
117+ echo "> foundation infra environment loaded (cached)"
118+ fi
119+ BASHEOF
59120fi
60- eval "$(direnv hook bash)"
61- EOF
62121
63122echo " === Antigravity Nix Feature Complete ==="
0 commit comments