Skip to content

Commit ca29892

Browse files
authored
Merge pull request #57 from flashbots/multi-lima
Support multiple copies of the repo on one machine
2 parents 9943346 + 1118f75 commit ca29892

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ measure-gcp: ## Export TDX measurements for GCP
5858
# Clean build artifacts
5959
clean: ## Remove cache and build artifacts
6060
rm -rf build/ mkosi.builddir/ mkosi.cache/ lima-nix/
61-
@if command -v limactl >/dev/null 2>&1 && limactl list | grep -q '^tee-builder'; then \
62-
echo "Stopping and deleting lima VM 'tee-builder'..."; \
63-
limactl stop tee-builder || true; \
64-
limactl delete tee-builder || true; \
61+
@REPO_DIR="$$(pwd)"; \
62+
REPO_HASH="$$(echo -n "$$REPO_DIR" | sha256sum | cut -c1-8)"; \
63+
LIMA_VM="tee-builder-$$REPO_HASH"; \
64+
if command -v limactl >/dev/null 2>&1 && limactl list | grep -q "^$$LIMA_VM"; then \
65+
echo "Stopping and deleting Lima VM '$$LIMA_VM'..."; \
66+
limactl stop "$$LIMA_VM" || true; \
67+
limactl delete "$$LIMA_VM" || true; \
6568
fi

scripts/env_wrapper.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
LIMA_VM="${LIMA_VM:-tee-builder}"
4+
# Check for dangling old-style tee-builder VM
5+
if command -v limactl &>/dev/null && limactl list 2>/dev/null | grep -q '^tee-builder '; then
6+
echo "WARNING: FOUND 'tee-builder' VM FROM BEFORE COMMIT 2b44885."
7+
echo "THIS VM IS NO LONGER USED. TO CLEAN IT UP, RUN:"
8+
echo " limactl stop tee-builder && limactl delete tee-builder"
9+
echo ""
10+
fi
11+
12+
# Generate a unique VM name based on the absolute path of this repo
13+
# This prevents conflicts when the same repo is cloned to multiple locations
14+
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
15+
REPO_HASH="$(echo -n "$REPO_DIR" | sha256sum | cut -c1-8)"
16+
LIMA_VM="${LIMA_VM:-tee-builder-$REPO_HASH}"
517

618
# Check if Lima should be used
719
should_use_lima() {
@@ -35,15 +47,15 @@ setup_lima() {
3547
args+=("--disk" "$LIMA_DISK")
3648
fi
3749

38-
echo -e "Creating $LIMA_VM VM..."
50+
echo -e "Creating Lima VM '$LIMA_VM' for $REPO_DIR..."
3951
# Portable way to expand array on bash 3 & 4
40-
limactl create -y --name "$LIMA_VM" ${args[@]+"${args[@]}"} lima.yaml
52+
limactl create -y --name "$LIMA_VM" ${args[@]+"${args[@]}"} "$REPO_DIR/lima.yaml"
4153
fi
4254

4355
# Start VM if not running
4456
status=$(limactl list "$LIMA_VM" --format "{{.Status}}")
4557
if [ "$status" != "Running" ]; then
46-
echo -e "Starting $LIMA_VM VM..."
58+
echo -e "Starting Lima VM '$LIMA_VM'..."
4759
limactl start -y "$LIMA_VM"
4860

4961
rm -f NvVars # Remove stray file created by QEMU
@@ -111,7 +123,7 @@ if should_use_lima; then
111123
echo
112124
fi
113125

114-
echo "Note: Lima VM is still running. To stop it, run: limactl stop $LIMA_VM"
126+
echo "Note: Lima VM '$LIMA_VM' is still running. To stop it, run: limactl stop $LIMA_VM"
115127
else
116128
if in_nix_env; then
117129
exec "${cmd[@]}"

0 commit comments

Comments
 (0)