Read .env values and pin tool versions
Use this guide when a project keeps secrets or machine-specific values in a .env file, or pins its tool versions with mise or direnv, and the lanes should use both.
::example{slug="workflows-dotenv"}
Pass .env values to services
Section titled “Pass .env values to services”The .env file sits next to the project file and stays out of Git. devlanes reads it for expressions and does not put its contents into any process, so name each variable a process needs:
global_env: ACME_API_TOKEN: "${{ env.ACME_API_TOKEN }}" SENTRY_DSN: "${{ env.SENTRY_DSN | default('') }}"global_envVariables for every service and task of the lane, above devlanes' own variables (PORT, DEVLANES_*) and below each unit's env and the profile's env. Use it for values many units share, such as a database URL built from ${{ infra.postgres.port }}. An entry without a value, such as one that reads a container a profile with infra: false left stopped, fails every service and task of the lane, so a value only some services need belongs in their env. devlanes exec leaves such an entry out and names it. Never set PORT here: it would replace every service's own port.
global_env.<name>Variables for every service and task of the lane, above devlanes' own variables (PORT, DEVLANES_*) and below each unit's env and the profile's env. Use it for values many units share, such as a database URL built from ${{ infra.postgres.port }}. An entry without a value, such as one that reads a container a profile with infra: false left stopped, fails every service and task of the lane, so a value only some services need belongs in their env. devlanes exec leaves such an entry out and names it. Never set PORT here: it would replace every service's own port.
Under global_env a value reaches every service and task of the lane. A variable missing from both the file and your shell stops the start, unless the expression gives a default as the second line does. A new worktree reads the primary worktree’s .env, as Files and folders describes.
Apply an edit
Section titled “Apply an edit”$ devlanes reloadThe reload restarts the services whose values changed.
Pin tool versions with mise or direnv
Section titled “Pin tool versions with mise or direnv”With a mise config such as mise.toml, or an allowed .envrc, in the worktree root, each service and task gets the tools and variables it sets. A config the tool does not trust yet is skipped with a note, so trust it and restart the services:
$ mise trust$ devlanes restartFor direnv, run direnv allow in place of mise trust.
If the app loads .env itself
Section titled “If the app loads .env itself”A service that loads .env itself keeps working. Most dotenv loaders leave a variable alone when it is already set, so the value the project file passes wins.