Skip to content

feat(env): support exec: commands and arrays in env_from - #3057

Open
plopoyop wants to merge 4 commits into
jetify-com:mainfrom
plopoyop:feature/env-from-sops
Open

plopoyop wants to merge 4 commits into
jetify-com:mainfrom
plopoyop:feature/env-from-sops

Conversation

@plopoyop

@plopoyop plopoyop commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds two ways to load environment variables in env_from, as suggested in review:

  • exec:<command> runs a command that prints a flat JSON object. Any secret manager works, e.g. exec:sops decrypt --output-type json secrets.enc.yaml, exec:op ..., or exec:vault kv get -format=json ... | jq .data.data.
  • Arrays: env_from accepts a list of .env files and exec: commands, merged in order. devbox.json env still overrides everything. Existing string values keep working.
{
  "packages": ["sops@latest"],
  "env": { "SOPS_AGE_KEY_FILE": "$PWD/.age/key.txt" },
  "env_from": [".env", "exec:sops decrypt --output-type json secrets.enc.yaml"]
}

How commands run:

  • The command runs with sh -c in the project directory. It gets the project environment, including earlier env_from sources and devbox.json env.
  • The PATH lists the profile, then runx, then the devbox PATH, then the host PATH (the host PATH is left out with --pure).
  • It gets the terminal for prompts (PIN, hardware key touch), but not piped input. Its stderr is shown.
  • Each command runs once per devbox command.
  • If a command fails or prints invalid output, devbox prints a warning, skips that source and still applies the others.
  • Nested values, PATH, and invalid names or values are skipped with a warning. Values are not $-expanded, but devbox.json env can reference them.

Values from commands are treated as secrets:

  • They are never written to disk. devbox shell gets them through the process environment, and the generated shellrc only holds references (export K="${__DEVBOX_SECRET_K}"; unset ...).
  • They are left out of the shellenv hash.
  • devbox.json variables that reference a secret are treated as secrets too.

How was it tested?

  • Unit tests:
    • JSON parsing;
    • process env and PATH order;
    • one run per command;
    • failure warnings;
    • merge order and secret tracking across sources;
    • earlier sources visible to later commands;
    • invalid keys and values;
    • background processes;
    • shell references for bash/zsh/fish, interactive and not;
    • shellrc contains no secrets;
    • hash ignores secrets.
  • Testscripts:
    • envfrom_exec: mock command, pipe, failure, .env + exec: array;
    • envfrom_sops_age: real age-encrypted yaml and dotenv files decrypted with exec:sops.
  • Existing envfrom and envfrom_jetify_cloud testscripts pass unchanged.
  • devbox run lint: 0 issues.

Community Contribution License

All community contributions in this pull request are licensed to the project
maintainers under the terms of the
Apache 2 License.

By creating this pull request, I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 License as stated in
the
Community Contribution License.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the earlier path-expansion issue is fixed.

Summary

Adds exec: commands and ordered arrays to env_from, while keeping command-provided secrets out of generated shell files.

  • Projects can load environment values from commands and ordered source lists.
  • Command-loaded secrets stay out of generated shell files and environment hashes.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Earlier .env sources] --> B[Expand source values]
  S[Earlier command secrets] --> B
  B --> C[Build command environment]
  C --> D[Run exec command once]
  D --> E[Merge output verbatim]
  E --> F[Apply config env]
  F --> G[Shell or command environment]
Loading

Reviews (6) · Last reviewed commit: "fix(env): expand .env values passed to e..." · Reviewed by Greptile

Comment thread internal/devbox/shell.go Resolved
Comment thread internal/devbox/sops.go Resolved
greptile-apps[bot]
greptile-apps Bot previously approved these changes Nov 15, 2026
@mikeland73 mikeland73 closed this Nov 17, 2026
@mikeland73 mikeland73 reopened this Nov 17, 2026
env_from accepts "sops:<path>" to load variables from a SOPS-encrypted
.yaml, .yml, .json or .env file, decrypted with the sops CLI from the
project packages, runx or the host PATH.

- Values are injected verbatim and devbox.json env can reference them.
- Decryption runs once per command; failures warn and empty the
  declared variables instead of keeping the host values.
- Secrets are never written to the devbox shell rc file: they reach the
  shell through its process env and are re-exported by reference.
Fish runs config.fish and the shellrc even when not interactive, so it
always gets the secrets by reference. The sops lookup now starts with the
profile and runx directories, as with OmitNixEnv the computed PATH
already contains the host PATH.
@plopoyop
plopoyop force-pushed the feature/env-from-sops branch from 6e28547 to b9cbaac Compare November 17, 2026 05:58
@greptile-apps
greptile-apps Bot dismissed their stale review November 17, 2026 05:58

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

greptile-apps[bot]
greptile-apps Bot previously approved these changes Nov 19, 2026
@mikeland73

Copy link
Copy Markdown
Collaborator

Instead of SOPS-specific support, could env_from accept exec: that prints a flat JSON object? sops becomes exec:sops decrypt --output-type json secrets.enc.yaml, and the process env, prompt handling, per-command cache and shell rc protections you built all still apply, without depending on one tool.

e.g.

{
  "packages": ["sops@latest"],
  "env": { "SOPS_AGE_KEY_FILE": "$PWD/.age/key.txt" },
  "env_from": "exec:sops decrypt --output-type json secrets.enc.yaml"
}

This would allow fetching secrets from any secret manager (later on we can figure out caching, perf etc). It would also allow combining non-secret env file and secrets.

thoughts?

@plopoyop

Copy link
Copy Markdown
Contributor Author

Instead of SOPS-specific support, could env_from accept exec: that prints a flat JSON object? sops becomes exec:sops decrypt --output-type json secrets.enc.yaml, and the process env, prompt handling, per-command cache and shell rc protections you built all still apply, without depending on one tool.

e.g.

{
  "packages": ["sops@latest"],
  "env": { "SOPS_AGE_KEY_FILE": "$PWD/.age/key.txt" },
  "env_from": "exec:sops decrypt --output-type json secrets.enc.yaml"
}

This would allow fetching secrets from any secret manager (later on we can figure out caching, perf etc). It would also allow combining non-secret env file and secrets.

thoughts?

Good idea, that's more flexible than a SOPS-only solution. I'll rework this branch to support exec:.

env_from now accepts an "exec:<command>" source that prints a flat JSON
object, as suggested in review, so any secret manager can be used. sops
becomes "exec:sops decrypt --output-type json <file>".

env_from also accepts an array of .env files and exec: commands, merged
in order. Values from commands keep the secret handling: they are never
written to disk and are passed to devbox shell by reference.
@greptile-apps
greptile-apps Bot dismissed their stale review November 21, 2026 15:31

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

@plopoyop plopoyop changed the title feat(env): support SOPS-encrypted files in env_from feat(env): support exec: commands and arrays in env_from Nov 21, 2026
@plopoyop

Copy link
Copy Markdown
Contributor Author

Done in 3ab2fbd: env_from now supports exec:<command> (flat JSON on stdout), and also accepts an array of .env files and commands merged in order, so non-secret env files and secrets can be combined. The sops: prefix is gone; sops is just exec:sops decrypt --output-type json <file>. I've updated the PR description.

One trade-off: on failure we can't unset the keys anymore (we no longer know them), so the source is skipped with a warning and the other sources still apply.

Comment thread internal/devbox/envfrom.go Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants