# Rebuild Mac Automation Tools from a Brewfile

Canonical: https://figment.so/blog/mac-agent-brewfile-rebuild

Dump a Brewfile from a working Mac with brew bundle dump, then run brew bundle install on the new one. Standard CLI tooling rebuilds on a Figment Intel Mac VM ($25 a month); arm64-only tools need an Apple silicon plan.

Capture a Brewfile from a working Mac with `brew bundle dump`, commit it, and run `brew bundle install --file=...` on the new machine to reinstall every tool with one command. This guide also shows how to detect drift on a running agent and which Figment plan to rebuild on. The commands come from the official [Homebrew Bundle documentation](https://docs.brew.sh/Brew-Bundle-and-Brewfile).

## Which Figment plan should I rebuild on?

Rebuild on the plan your tools need. Standard CLI tooling (Homebrew, Python, Node.js, Ruby, Go, curl, jq, git) runs on the Intel Mac VM, which is the cheapest clean slate.

| Workload | Plan | Month | Day | Hour |
|---|---|---:|---:|---:|
| CLI tools, Python, Node.js, Ruby, Go, curl, jq: Intel-compatible toolchains | [Intel Mac VM](/mac-hosting#intel-vm) (4 shared vCPUs, 4GB, 80GB, macOS Sequoia) | $25 | $2 | $0.15 |
| arm64-only binaries, Apple-silicon-only casks, Xcode 26.4 or later | [Apple Silicon Mac VM](/mac-hosting#apple-silicon-vm) (4 shared vCPUs, 4GB, 65GB) | $39 | $6 | $0.40 |
| Heavy builds, large media tools, isolated agents | [Dedicated M4 Pro 48 GB](/mac-hosting#dedicated-m4-pro) (whole Mac, M4 Pro, 48GB, 512GB) | $349 | Monthly only | Monthly only |

The Intel VM runs compatible Intel toolchains, including Xcode 26.0 to 26.3 on macOS Sequoia, per Apple's [Porting your macOS apps to Apple silicon](https://developer.apple.com/documentation/apple-silicon/porting-your-macos-apps-to-apple-silicon) guidance. It cannot run arm64-only binaries or visionOS. Every plan gives you administrator access to your own Mac or VM. The Intel Mac VM and the Dedicated M4 Pro include SSH, encrypted remote desktop and browser access; the Apple Silicon Mac VM has the browser desktop and SSH. Figment runs the Mac and network layer; the Brewfile, your tools and your agent are yours to manage.

## What does a Brewfile capture, and what does it miss?

`brew bundle dump` records installed formulae, casks, taps and (if `mas` is installed) Mac App Store entries. It does **not** capture:

- Python `pip` packages, npm global modules, RubyGems, Go modules
- Files placed under `/usr/local` or `/opt/homebrew` manually
- macOS system settings, launchd plists, cron entries
- Shell dotfiles or editor config

Pair the Brewfile with a `requirements.txt`, `package.json` or `go.mod` committed to the same repository for a complete rebuild. `brew bundle` does not produce a `Brewfile.lock.json`, and Homebrew does not pin to specific upstream versions. Reproducibility comes from the Brewfile text plus your language-level lockfiles, not from a Homebrew lockfile.

You need Homebrew on the source machine, terminal access to it (SSH on a Figment Mac), and write access to the repository that will own the Brewfile.

## How do I generate and version the Brewfile?

Run `brew bundle dump` on the known-good machine:

```bash
brew bundle dump \
  --describe \
  --file="$HOME/dotfiles/Brewfile" \
  --force
```

`--describe` writes a comment with each package's description, and `--force` overwrites an existing file. The output is a small, readable Ruby-style manifest:

```ruby
# Brewfile: automation-agent v1.4.2, 2026-11-10

tap "homebrew/bundle"

brew "curl"
brew "jq"
brew "python@3.12"
brew "node@20"
brew "git"
brew "gh"
brew "shellcheck"
brew "ffmpeg"
brew "imagemagick"
brew "mas"
```

Commit it with a dated header, so future readers can trace which agent generation the file represents.

## How do I install it on a fresh Figment Mac?

Install Homebrew on the new machine with the installer at [brew.sh](https://brew.sh), then run:

```bash
brew bundle install --file="$HOME/dotfiles/Brewfile"
```

`brew bundle install` is idempotent: it skips what is already installed. If a line fails, Homebrew continues with the rest and exits non-zero at the end, so read the summary and re-run after each fix. For a pre-job gate, combine install with a check:

```bash
set -euo pipefail
brew bundle install --file="$HOME/dotfiles/Brewfile"
brew bundle check  --file="$HOME/dotfiles/Brewfile" --verbose
```

`brew bundle check --verbose` lists every missing dependency and exits non-zero if the Brewfile is not fully satisfied, without changing the system. Treat a non-zero exit as a hard failure of the job, and do not record it as a successful run.

## How do I detect drift?

Drift happens when someone upgrades, installs or removes a package outside the Brewfile. Two commands surface it:

```bash
# What is installed that the Brewfile does not list?
brew bundle cleanup --file="$HOME/dotfiles/Brewfile"
# (add --force to actually remove the extras)

# Which installed formulae have newer upstream versions?
brew outdated
```

A small drift report script writes both to a file you can upload as a CI artifact:

```bash
#!/usr/bin/env bash
# version-drift-report.sh
set -euo pipefail

STAMP=$(date -u +%Y%m%dT%H%M%SZ)
REPORT="${TMPDIR:-/tmp}/drift-${STAMP}-$$.txt"
BREWFILE="$HOME/dotfiles/Brewfile"

{
  echo "=== Environment inventory: ${STAMP} ==="
  sw_vers
  echo
  echo "--- Brewfile formulae: installed versions ---"
  grep '^brew ' "$BREWFILE" | awk -F'"' '{print $2}' | while IFS= read -r f; do
    v=$(brew list --versions "$f" 2>/dev/null || echo "NOT INSTALLED")
    printf "%-30s %s\n" "$f" "$v"
  done
  echo
  echo "--- Extras not in Brewfile ---"
  brew bundle cleanup --file="$BREWFILE" || true
  echo
  echo "--- Outdated packages ---"
  brew outdated || true
} > "$REPORT"

echo "Drift report: $REPORT"
```

The output is a reproducible environment inventory: exact installed versions, macOS build and timestamp. Store a copy next to each production build artifact, so a specific output ties back to the exact toolchain that produced it.

## What if the rebuild fails?

Match the symptom in this table:

| Symptom | Diagnosis | Fix |
|---|---|---|
| `brew bundle install` exits non-zero | Read the per-line failure summary; `brew doctor` | Fix tap or formula name; re-run (idempotent) |
| `brew bundle check` fails after install | Cask needs a GUI session the agent lacks | Install the cask in a remote desktop session or drop it from the agent Brewfile |
| Wrong formula version pinned | `brew list --versions <formula>` | Switch to a versioned formula (e.g. `python@3.12`) and re-dump |
| Drift found | `brew bundle cleanup` shows extras | Add them to the Brewfile or remove with `--force` |
| New Mac has no Homebrew | Installer script at [brew.sh](https://brew.sh) | Install Homebrew first, then run `brew bundle install` |

## What does a rebuild cost?

A rebuild window on the Intel Mac VM costs by the hour or day: a two-week window on daily plans is 14 × $2 = $28, and one month is $25. Disconnecting or shutting down macOS does not stop billing, so stop the Mac in Figment when the window closes. Rebuild time depends on package count and Homebrew's download speed from your region, so measure it on your own Brewfile instead of relying on a quoted benchmark.

If you run several Macs, the same Brewfile rebuilds each of them from one commit. Pin a version tag in the file header for each deployment, so a rollback is obvious. For a team with several Macs, Figment quotes enterprise plans on a call. Keep the Brewfile in your repository: Figment does not back up your Mac, so the repository stays the source of truth for the toolchain.

## Where do I start?

Pick a plan from the [Mac hosting plans](/mac-hosting), install Homebrew over SSH, and run `brew bundle install`.

**Related guides:**
- [Mac agent browser profiles](/blog/mac-agent-browser-profiles)
- [Mac agent artifact delivery](/blog/mac-agent-artifact-delivery)
- [Mac GitHub Actions self-hosted runner](/blog/mac-github-actions-self-hosted-runner)
