Skip to content

Commit cbce22c

Browse files
committed
feat: sync features with verified local versions (v1.1.0)
1 parent 0ac9627 commit cbce22c

12 files changed

Lines changed: 351 additions & 92 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"id": "antigravity-nix",
3+
"version": "1.0.0",
4+
"name": "Antigravity Nix (Local)",
5+
"description": "Local version of Nix feature optimized for Zero-Prompt UX",
6+
"options": {}
7+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
echo "=== Antigravity Nix Feature (Local) ==="
5+
6+
# --- 1. Install essential packages (Minus Direnv) ---
7+
echo "Installing essential packages..."
8+
apt-get update
9+
apt-get install -y --no-install-recommends \
10+
sudo \
11+
git \
12+
wget \
13+
curl \
14+
ca-certificates \
15+
xz-utils \
16+
gnupg \
17+
procps \
18+
pass
19+
rm -rf /var/lib/apt/lists/*
20+
21+
# --- 2. Create vscode user ---
22+
echo "Creating vscode user..."
23+
if ! id -u vscode > /dev/null 2>&1; then
24+
groupadd -g 1000 vscode
25+
useradd -u 1000 -g 1000 -m -s /bin/bash vscode
26+
fi
27+
echo "vscode ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/vscode
28+
chmod 0440 /etc/sudoers.d/vscode
29+
30+
# --- 3. Pre-create /nix with correct ownership ---
31+
echo "Setting up /nix directory..."
32+
mkdir -p /nix
33+
chown 1000:1000 /nix
34+
35+
# --- 4. Install Nix (single-user mode as vscode) ---
36+
echo "Installing Nix..."
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
41+
42+
# --- 5. Configure Nix for flakes ---
43+
echo "Configuring Nix for flakes..."
44+
mkdir -p /etc/nix
45+
cat > /etc/nix/nix.conf << 'EOF'
46+
experimental-features = nix-command flakes
47+
build-users-group =
48+
EOF
49+
50+
# --- 6. Add Nix to profile for all shells (Zero-Prompt Ready) ---
51+
echo "Adding Nix to shell profile..."
52+
rm -f /etc/profile.d/nix.sh
53+
cat >> /etc/profile.d/nix.sh << 'EOF'
54+
if [ -e '/home/vscode/.nix-profile/etc/profile.d/nix.sh' ]; then
55+
. '/home/vscode/.nix-profile/etc/profile.d/nix.sh'
56+
fi
57+
EOF
58+
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
120+
fi
121+
122+
echo "=== Antigravity Nix Feature Complete ==="
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"id": "gcloud",
3+
"version": "1.0.0",
4+
"name": "Google Cloud SDK (Local)",
5+
"description": "Local version of Gcloud feature optimized for non-root users",
6+
"options": {}
7+
}

features/gcloud/install.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
echo "=== Google Cloud SDK Feature (Local) ==="
5+
6+
# Install dependencies
7+
apt-get update
8+
apt-get install -y --no-install-recommends curl ca-certificates python3 gnupg
9+
rm -rf /var/lib/apt/lists/*
10+
11+
# Install Gcloud
12+
if [ ! -d "/usr/local/google-cloud-sdk" ]; then
13+
echo "Downloading Google Cloud SDK..."
14+
# Note: Install dir /usr/local will create /usr/local/google-cloud-sdk
15+
curl -fsSL https://sdk.cloud.google.com | bash -s -- --install-dir=/usr/local --disable-prompts
16+
fi
17+
18+
# Link binaries to /usr/local/bin
19+
echo "Linking Gcloud binaries to /usr/local/bin..."
20+
for bin in /usr/local/google-cloud-sdk/bin/*; do
21+
if [ -f "$bin" ] && [ -x "$bin" ]; then
22+
ln -sf "$bin" "/usr/local/bin/$(basename "$bin")"
23+
fi
24+
done
25+
26+
echo "Google Cloud SDK installed successfully!"
27+
gcloud version
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"id": "pulumi",
3+
"version": "1.0.0",
4+
"name": "Pulumi (Local)",
5+
"description": "Local version of Pulumi feature optimized for non-root users",
6+
"options": {
7+
"version": {
8+
"type": "string",
9+
"default": "latest",
10+
"description": "Pulumi version"
11+
}
12+
}
13+
}

features/pulumi/install.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
VERSION=${VERSION:-"latest"}
5+
6+
echo "=== Pulumi Feature (Local) ==="
7+
echo "Target version: ${VERSION}"
8+
9+
# Install dependencies
10+
apt-get update
11+
apt-get install -y --no-install-recommends curl ca-certificates
12+
rm -rf /var/lib/apt/lists/*
13+
14+
# Set installation directory
15+
TMP_PULUMI_HOME="/tmp/pulumi_install"
16+
mkdir -p "$TMP_PULUMI_HOME"
17+
18+
export HOME="$TMP_PULUMI_HOME"
19+
if [ "${VERSION}" = "latest" ]; then
20+
curl -fsSL https://get.pulumi.com | bash
21+
else
22+
curl -fsSL https://get.pulumi.com | bash -s -- --version "${VERSION}"
23+
fi
24+
25+
# Move to /usr/local/pulumi
26+
mkdir -p /usr/local/pulumi
27+
if [ -d "$TMP_PULUMI_HOME/.pulumi/bin" ]; then
28+
cp -r "$TMP_PULUMI_HOME/.pulumi/bin" /usr/local/pulumi/
29+
else
30+
echo "ERROR: Pulumi binaries not found in $TMP_PULUMI_HOME/.pulumi/bin"
31+
exit 1
32+
fi
33+
rm -rf "$TMP_PULUMI_HOME"
34+
35+
# Ensure all users can read/execute
36+
chmod -R a+rx /usr/local/pulumi
37+
38+
# Link binaries to /usr/local/bin
39+
echo "Linking Pulumi binaries to /usr/local/bin..."
40+
for bin in /usr/local/pulumi/bin/*; do
41+
ln -sf "$bin" "/usr/local/bin/$(basename "$bin")"
42+
done
43+
44+
echo "Pulumi installed successfully!"
45+
/usr/local/bin/pulumi version
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{
22
"id": "antigravity-nix",
33
"version": "1.1.0",
4-
"name": "Nix with Flakes",
5-
"description": "Creates vscode user with passwordless sudo, installs Nix with flakes, and essential tools",
4+
"name": "Antigravity Nix",
5+
"description": "Creates vscode user, installs Nix with flakes, and provides Zero-Prompt UX",
66
"options": {},
7-
"containerEnv": {
8-
"NIX_CONF_DIR": "/etc/nix"
9-
}
7+
"containerUser": "vscode"
108
}

src/features/antigravity-nix/install.sh

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
2-
set -e
2+
set -ex
33

44
echo "=== Antigravity Nix Feature ==="
55

6-
# --- 1. Install essential packages ---
6+
# --- 1. Install essential packages (Minus Direnv) ---
77
echo "Installing essential packages..."
88
apt-get update
99
apt-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
2019
rm -rf /var/lib/apt/lists/*
2120

@@ -35,7 +34,10 @@ chown 1000:1000 /nix
3534

3635
# --- 4. Install Nix (single-user mode as vscode) ---
3736
echo "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 ---
4143
echo "Configuring Nix for flakes..."
@@ -45,19 +47,76 @@ experimental-features = nix-command flakes
4547
build-users-group =
4648
EOF
4749

48-
# --- 6. Add Nix to profile for all shells ---
50+
# --- 6. Add Nix to profile for all shells (Zero-Prompt Ready) ---
4951
echo "Adding Nix to shell profile..."
52+
rm -f /etc/profile.d/nix.sh
5053
cat >> /etc/profile.d/nix.sh << 'EOF'
5154
if [ -e '/home/vscode/.nix-profile/etc/profile.d/nix.sh' ]; then
5255
. '/home/vscode/.nix-profile/etc/profile.d/nix.sh'
5356
fi
5457
EOF
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
59120
fi
60-
eval "$(direnv hook bash)"
61-
EOF
62121

63122
echo "=== Antigravity Nix Feature Complete ==="

src/features/gcloud/devcontainer-feature.json

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
{
22
"id": "gcloud",
3-
"version": "1.0.1",
4-
"name": "Google Cloud CLI",
5-
"description": "Installs the Google Cloud CLI via official repositories",
6-
"options": {
7-
"version": {
8-
"type": "string",
9-
"description": "GCloud version (latest, or specific version)",
10-
"default": "latest"
11-
}
12-
},
3+
"version": "1.1.0",
4+
"name": "Google Cloud SDK",
5+
"description": "Installs the Google Cloud CLI via official installer script",
6+
"options": {},
137
"installsAfter": [
148
"ghcr.io/duizendstra/devcontainer-features/antigravity-nix"
159
]

0 commit comments

Comments
 (0)