Skip to main content

Module env

Module env 

Source
Expand description

Workspace environments: where the programs and libraries a run needs come from.

Models fail most often not on the task but on a missing tool (jq: not found, No module named 'matplotlib', a pip install that can’t work on NixOS). So every run_command / run_python call is prepared by Envs. If the user opted the workspace into a container (Docker/Podman; asked once when it has a devcontainer.json), the call runs there. Otherwise Envs stacks layers onto the clean sandbox environment, first match winning:

  1. Installed: packages the model asked for with install_packages, kept per workspace under <data>/envs/ (Nix: one buildEnv, a GC root, nixpkgs pinned; without Nix: a pixi manifest of conda-forge packages).
  2. Project venv: a .venv / venv in the workspace (any OS).
  3. Project environments (Project): what the workspace declares itself, loaded once the user agreed (choices, asked once per workspace), then cached until its files change — a flake.nix / shell.nix dev shell (nix print-dev-env, shellHook included), a pixi project (pixi shell-hook --json), mise tools (mise env --json).
  4. Support: what a package manager’s own CLI needs inside the sandbox, so the model can also run nix shell nixpkgs#foo --command … itself (store, daemon socket, config, a persistent eval cache), and Homebrew’s bin.

The last resort, system (Homebrew / winget, system-wide), always needs a person’s approval. Failed output gets a hints line that names the one tool to call, because small models follow an explicit next step far better than prose. Design and plans: docs/environments.md.

Re-exports§

pub use command::CommandProvider;

Modules§

choices
What the user decided per workspace: load its project environment or not, run its commands in a container or not. A workspace is identified by its canonical path.
command
Environment providers plugins declare in their manifest (environments): when the workspace has one of the provider’s files, run its command in the workspace (sandboxed, with network, may write the workspace) and read the environment it prints as JSON — {"PATH": "/x/bin:…", "NAME": "value"} (mise’s form) or {"environment_variables": {…}} (pixi’s). Asked once per workspace and cached until its files change, like byob’s own.
container
Containers: a workspace can run its commands inside one long-lived Docker or Podman container instead of on this machine (opt-in per workspace; asked once when the workspace has a devcontainer.json).
devcontainer
What a workspace’s container is made from: its .devcontainer/devcontainer.json (or .devcontainer.json), else the default image.
hints
One-line “what to do next” for failed runs that lack a program or Python library. Small models recover far better from a concrete tool call than from general advice.
nix
Nix: the workspace’s own dev shell, packages installed on request, and a nix CLI that works inside the sandbox.
pixi
pixi as the install_packages backend where there’s no Nix (Linux and macOS without it, Windows): conda-forge packages, per workspace, without root.
project
Project environments from tools that print their environment as JSON, so they work the same on Linux, macOS and Windows:
system
The last resort: installing system-wide with Homebrew (macOS, Linuxbrew) or winget (Windows), through install_system_packages. Never the default — it changes the machine for every program and user, outside the workspace, and byob can’t undo it — so a person must approve every call (no grant or --auto-approve does), and only for packages the workspace installer (Nix, pixi) couldn’t provide, or where there is none.

Structs§

Envs
The package managers found on this machine, the per-workspace state they keep, and what the user decided per workspace.
Found
The package managers and tools found on this machine. Found::detect looks on PATH; tests build one by hand to hide what they don’t want used (e.g. Nix, to test the pixi installer on a machine that has both).
Installed
The result of installing packages.
Layer
Changes a run gets: PATH entries in front of the host’s, variables, and sandbox access.

Enums§

ProjectMode
Whether project environments load (see WORKSPACE_ENV).

Constants§

KEEP_VARS
Variables a layer must never set: the sandbox’s own home, temp and cache folders, and what only makes sense inside a Nix build (mirrors nix develop’s ignore list).
NATIVE_PROVIDERS
byob’s own providers, by the id plugin manifests name them with (environments[].native), and container (dev containers, which aren’t an EnvProvider but switch the same way).
WORKSPACE_ENV
Override the per-workspace question: BYOB_WORKSPACE_ENV=off never loads a workspace’s own environment (installed packages and the Nix CLI still work), on loads it without asking. Unset (or ask): ask once per workspace and remember the answer.

Traits§

EnvProvider
An environment a workspace declares in a project file (flake.nix, pixi.toml, mise.toml, …): loaded once (slow, may download), then cached until its files change.
Runner
Runs a sandboxed job for a provider (the tool’s own sandbox, with the support layer).

Functions§

fnv64
FNV-1a: a stable 64-bit hash for cache keys (std’s hasher may change between releases).
join_path
PATH for a run: prefix then the host’s.
keep_var
venv_layer
A Python virtual environment in the workspace (.venv or venv): its scripts folder goes first on PATH, as activate would do.