|
| 1 | +--- |
| 2 | +name: devbox |
| 3 | +description: Devbox expert guidance. Use when creating isolated development environments, managing project dependencies with Nix packages, authoring devbox.json, writing scripts or services, or generating Dockerfiles and devcontainers from a devbox project. |
| 4 | +metadata: |
| 5 | + docs: |
| 6 | + - "https://www.jetify.com/devbox/docs" |
| 7 | + - "https://github.com/jetify-com/devbox" |
| 8 | + pathPatterns: |
| 9 | + - 'devbox.json' |
| 10 | + - 'devbox.lock' |
| 11 | + - '.devbox/**' |
| 12 | + bashPatterns: |
| 13 | + - '^\s*devbox(?:\s|$)' |
| 14 | +--- |
| 15 | + |
| 16 | +# Devbox Skill |
| 17 | + |
| 18 | +[Devbox](https://github.com/jetify-com/devbox) creates isolated, reproducible development environments powered by Nix. You declare packages and scripts in a `devbox.json`; Devbox materializes a shell where everyone on the team gets the exact same tool versions without polluting the host machine. Use `devbox <command> -h` for full flag details on any command. |
| 19 | + |
| 20 | +## Quick Start |
| 21 | + |
| 22 | +```bash |
| 23 | +curl -fsSL https://get.jetify.com/devbox | bash # install devbox |
| 24 | +devbox init # create devbox.json in cwd |
| 25 | +devbox add go@1.22 nodejs@20 # add packages (name@version) |
| 26 | +devbox shell # enter the isolated shell |
| 27 | +devbox run <script> # run a script from devbox.json |
| 28 | +``` |
| 29 | + |
| 30 | +Packages resolve against the Nix package registry. Browse versions at [nixhub.io](https://www.nixhub.io). |
| 31 | + |
| 32 | +## The `devbox.json` File |
| 33 | + |
| 34 | +The project's source of truth. Minimum viable file: |
| 35 | + |
| 36 | +```json |
| 37 | +{ |
| 38 | + "packages": ["go@1.22", "nodejs@20"], |
| 39 | + "shell": { |
| 40 | + "init_hook": ["echo 'Welcome'"], |
| 41 | + "scripts": { |
| 42 | + "test": "go test ./...", |
| 43 | + "build": ["go build ./...", "echo done"] |
| 44 | + } |
| 45 | + }, |
| 46 | + "env": { |
| 47 | + "GOENV": "off", |
| 48 | + "PATH": "$PWD/bin:$PATH" |
| 49 | + } |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +- `packages`: array of `name@version` strings, or an object with per-package `platforms` / `excluded_platforms` / `outputs` / `patch` settings. |
| 54 | +- `shell.init_hook`: commands run every time the environment starts (both `devbox shell` and `devbox run`). Keep it fast — it runs often. |
| 55 | +- `shell.scripts`: named commands invoked with `devbox run <name>`. A value can be a string or an array of strings executed in order. |
| 56 | +- `env`: extra env vars. Only `$PATH` and `$PWD` are expanded; no other variable expansion or command substitution. |
| 57 | +- `include`: plugin references (e.g. `"plugin:nginx"`, `"path:./mydir"`, `"github:owner/repo"`). |
| 58 | + |
| 59 | +See `references/devbox-json.md` for the full schema. |
| 60 | + |
| 61 | +## Decision Tree |
| 62 | + |
| 63 | +Use this to route to the correct sub-topic: |
| 64 | + |
| 65 | +- **Add or remove a package** → `devbox add <pkg>@<ver>` / `devbox rm <pkg>`. See `references/packages.md`. |
| 66 | +- **Enter an isolated shell** → `devbox shell`. Add `--pure` for a shell that inherits almost nothing from the host. |
| 67 | +- **Run a task** → `devbox run <script>`. Pass arguments after `--` (e.g. `devbox run -- cowsay -d hi`). See `references/scripts-services.md`. |
| 68 | +- **Install all packages in CI** → `devbox install` (no shell). Pair with `actions/cache` keyed on `devbox.lock`. |
| 69 | +- **Update packages** → `devbox update` (all) or `devbox update <pkg>` (one). Use `--no-install` to update the lockfile only. |
| 70 | +- **Find a package** → `devbox search <pkg>`. |
| 71 | +- **Inspect installed packages** → `devbox list` / `devbox info <pkg>`. |
| 72 | +- **Long-running services (dbs, workers)** → `devbox services start|stop|ls|attach`. See `references/scripts-services.md`. |
| 73 | +- **Global tools (available everywhere)** → `devbox global add|rm|list`. See `references/global-and-templates.md`. |
| 74 | +- **Bootstrap from a template** → `devbox create --template <name>` (use `--show-all` to list templates). |
| 75 | +- **Generate Dockerfile / devcontainer / direnv** → `devbox generate dockerfile|devcontainer|direnv|alias|readme`. |
| 76 | +- **Load env into the host shell** → `eval "$(devbox shellenv)"`, or `devbox generate direnv` for automatic loading. |
| 77 | +- **Secrets (Jetify Cloud)** → `devbox secrets init|set|list|download|upload`. |
| 78 | +- **Multiple envs (dev/prod/preview)** → `--environment <name>` flag. |
| 79 | +- **Multi-project repos** → `--all-projects` on `run` and `update`; `--sync-lock` on `update`. |
| 80 | + |
| 81 | +## Critical: Lockfile Hygiene |
| 82 | + |
| 83 | +`devbox.lock` pins exact Nix store paths for every package. **Always commit it.** Without it, teammates and CI will get different versions. |
| 84 | + |
| 85 | +- `devbox install --tidy-lockfile` repairs missing store paths. |
| 86 | +- `devbox update --sync-lock` reconciles lockfiles across multiple projects in one repo. |
| 87 | +- Do not hand-edit `devbox.lock`. |
| 88 | + |
| 89 | +## Integrating with the Host Shell |
| 90 | + |
| 91 | +`devbox shell` spawns a subshell, which is noisy for daily work. Two better options: |
| 92 | + |
| 93 | +1. **direnv**: `devbox generate direnv` writes a `.envrc` so entering the directory auto-loads the environment. Requires `direnv` installed on the host. |
| 94 | +2. **shellenv**: `eval "$(devbox shellenv)"` inline-loads the environment into the current shell. Useful in CI or one-off scripts. |
| 95 | + |
| 96 | +## CI/CD |
| 97 | + |
| 98 | +Typical GitHub Actions pattern: |
| 99 | + |
| 100 | +```yaml |
| 101 | +- uses: jetify-com/devbox-install-action@v0.13.0 |
| 102 | + with: |
| 103 | + enable-cache: 'true' |
| 104 | +- run: devbox run test |
| 105 | +``` |
| 106 | +
|
| 107 | +Without the action, use `devbox install` + cache `~/.nix-*` and `.devbox/` keyed on `devbox.lock`. Avoid `devbox shell` in CI — use `devbox run <cmd>` (non-interactive) or `eval "$(devbox shellenv)"` instead. |
| 108 | + |
| 109 | +## Anti-Patterns |
| 110 | + |
| 111 | +- **Running devbox without a lockfile committed.** Defeats reproducibility. Commit `devbox.lock` alongside `devbox.json`. |
| 112 | +- **Using unversioned packages in production configs** (e.g. `"go"` instead of `"go@1.22"`). The resolver will pick whatever `@latest` resolves to the day you first install it; `devbox update` is the only way to bump it. Pin versions. |
| 113 | +- **Shell substitution in `env` values.** Only `$PATH` / `$PWD` expand. Put dynamic logic in `init_hook` instead. |
| 114 | +- **Heavy work in `init_hook`.** It runs on *every* `devbox run`, not just shell entry. Keep it to env mutations; move builds to scripts. |
| 115 | +- **`devbox shell` inside scripts or CI.** Blocks on an interactive prompt. Use `devbox run` or `devbox shellenv` instead. |
| 116 | +- **Editing `devbox.lock` by hand.** Let `devbox update`, `devbox install --tidy-lockfile`, or `devbox add` regenerate it. |
| 117 | +- **Forgetting `--` before flags to the target command.** `devbox run cowsay -d hi` tries to parse `-d` as a devbox flag. Use `devbox run -- cowsay -d hi`. |
| 118 | +- **Mixing `devbox` and `devbox global`.** `global` manages a separate config at `devbox global path` — project installs never leak into it, and vice versa. |
| 119 | + |
| 120 | +## Common Recipes |
| 121 | + |
| 122 | +- **New Go project**: `devbox init && devbox add go@latest && devbox shell` |
| 123 | +- **Dockerize**: `devbox generate dockerfile` produces a `Dockerfile` that replicates the shell. |
| 124 | +- **Reproduce in a devcontainer**: `devbox generate devcontainer` writes `.devcontainer/` for VS Code. |
| 125 | +- **Share a global toolset**: `devbox global push` (to Jetify Cloud or a git repo); teammates run `devbox global pull`. |
| 126 | +- **Run Postgres for local dev**: `devbox add postgresql` then `devbox services up postgresql`. |
0 commit comments