fix(nix): honor NIXPKGS_ALLOW_UNFREE/INSECURE in print-dev-env#2907
Open
mikeland73 wants to merge 2 commits into
Open
fix(nix): honor NIXPKGS_ALLOW_UNFREE/INSECURE in print-dev-env#2907mikeland73 wants to merge 2 commits into
mikeland73 wants to merge 2 commits into
Conversation
devbox shell computes its environment with `nix print-dev-env`, which runs in pure mode by default and therefore ignores the NIXPKGS_ALLOW_UNFREE and NIXPKGS_ALLOW_INSECURE environment variables. As a result, unfree (or insecure) flake inputs fail to evaluate inside a devbox shell even when the user sets NIXPKGS_ALLOW_UNFREE=1, while building and installing the same packages works because those code paths already pass --impure. Run print-dev-env with --impure (and the corresponding allow-unfree / allow-insecure env) when the user has opted in via those environment variables. Pure mode is kept otherwise so Nix evaluation caching still applies for the common case. The existing IMPURE_PRINT_DEV_ENV feature flag continues to force impure mode unconditionally. Fixes #2196 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KJZ8U5cYG5xLc4caCHt9jg
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to make devbox shell honor NIXPKGS_ALLOW_UNFREE and NIXPKGS_ALLOW_INSECURE when computing the shell environment via nix print-dev-env, by switching to --impure only when the user opts into unfree/insecure evaluation (or when the existing feature flag forces impure mode).
Changes:
- Add
IsUnfreeAllowed()alongside the existingIsInsecureAllowed()env parsing. - Introduce
usePrintDevEnvImpure()and use it to decide whether to runnix print-dev-envwith--impure. - Add unit tests for
IsUnfreeAllowed()andusePrintDevEnvImpure().
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| internal/nix/nix.go | Adds usePrintDevEnvImpure() and conditionally runs nix print-dev-env with --impure and an explicit environment. |
| internal/nix/eval.go | Adds IsUnfreeAllowed() to detect opt-in via NIXPKGS_ALLOW_UNFREE. |
| internal/nix/nix_test.go | Adds tests validating env-var parsing and the impure decision logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Only inject the allow-unfree / allow-insecure variables the user actually opted into, instead of forcing both. When impure mode is enabled solely via the IMPURE_PRINT_DEV_ENV feature flag, the child environment is left inheriting the parent unchanged. - Also honor NIXPKGS_ALLOW_UNFREE / NIXPKGS_ALLOW_INSECURE set in devbox.json's "env" block, not just the process environment. These are resolved in execPrintDevEnv (before config env is otherwise merged) and threaded through PrintDevEnvArgs. - Make the impure-decision unit test hermetic with respect to the IMPURE_PRINT_DEV_ENV feature flag, and cover the feature-flag path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KJZ8U5cYG5xLc4caCHt9jg
Collaborator
Author
|
Thanks for the review — addressed all three points in
Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2196.
devbox shellcomputes its environment withnix print-dev-env, which runs in pure mode by default. Pure mode ignores theNIXPKGS_ALLOW_UNFREEandNIXPKGS_ALLOW_INSECUREenvironment variables, so unfree (or insecure) flake inputs fail to evaluate inside a devbox shell — even when the user runsNIXPKGS_ALLOW_UNFREE=1 devbox shellor sets it indevbox.json'senv.This is inconsistent with the rest of devbox: building and installing packages (
internal/nix/build.go,profiles.go,cache.go,store.go) already pass--impuretogether with the allow-unfree/insecure env, so those flows work. Onlyprint-dev-envwas left pure — gated behind theIMPURE_PRINT_DEV_ENVfeature flag, which is disabled by default because--impuredisables Nix's evaluation caching and makes the command slower.Fix
Run
print-dev-envwith--impure(and the corresponding allow-unfree / allow-insecure environment) when the user has actually opted into unfree or insecure packages viaNIXPKGS_ALLOW_UNFREE/NIXPKGS_ALLOW_INSECURE. Pure mode — and its caching benefit — is preserved for everyone else, so there is no performance regression for the common case. The existingIMPURE_PRINT_DEV_ENVfeature flag still forces impure mode unconditionally.internal/nix/eval.go: addIsUnfreeAllowed(), mirroring the existingIsInsecureAllowed().internal/nix/nix.go: extract the impure decision intousePrintDevEnvImpure()(feature flag OR unfree opt-in OR insecure opt-in) and, when impure, setcmd.Envwith the allow-unfree/insecure vars, matching the other Nix call sites.internal/nix/nix_test.go: unit tests forIsUnfreeAllowedandusePrintDevEnvImpureacross the env-var combinations.How was it tested?
go test ./internal/nix/ -run 'TestIsUnfreeAllowed|TestUsePrintDevEnvImpure'— passes.go build ./...andgo vet ./internal/nix/— clean.TestConfigIsUserTrusted, require a realnixbinary that isn't present in the CI sandbox and are unrelated to this change.)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.
cc @eyevanovich (issue reporter)
🤖 Generated with Claude Code
https://claude.ai/code/session_01KJZ8U5cYG5xLc4caCHt9jg
Generated by Claude Code