Skip to content

Commit c314509

Browse files
authored
Aadd --impure flag when calling print-dev-env (#2279)
## Summary Add `--impure` to the `print-dev-env` command, allowing flakes to access environment variables also in this step. Without this change, a flake that needs an env var to work will correctly build but then a shell could not be created. This also solves #2196, signifying that other people encountered a similar problem. ## How was it tested? Both by ``` devbox run test ``` and manually, building the tool and locally checking that a flake would pick up variables (with `builtins.getEnv`) when activating a shell. --------- Signed-off-by: Federico Cergol <[email protected]>
1 parent dd9d373 commit c314509

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2024 Jetify Inc. and contributors. All rights reserved.
2+
// Use of this source code is governed by the license in the LICENSE file.
3+
4+
package featureflag
5+
6+
// ImpurePrintDevEnv controls whether the `devbox print-dev-env` command
7+
// will be called with the `--impure` flag.
8+
// Using the `--impure` flag will have two consequences:
9+
// 1. All environment variables will be passed to nix, this will enable
10+
// the usage of flakes that rely on environment variables.
11+
// 2. It will disable nix caching, making the command slower.
12+
var ImpurePrintDevEnv = disable("IMPURE_PRINT_DEV_ENV")

internal/nix/nix.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"time"
2121

2222
"github.com/pkg/errors"
23+
"go.jetpack.io/devbox/internal/boxcli/featureflag"
2324
"go.jetpack.io/devbox/internal/boxcli/usererr"
2425
"go.jetpack.io/devbox/internal/redact"
2526
"golang.org/x/mod/semver"
@@ -74,9 +75,11 @@ func (*Nix) PrintDevEnv(ctx context.Context, args *PrintDevEnvArgs) (*PrintDevEn
7475
}
7576

7677
if len(data) == 0 {
77-
cmd := command("print-dev-env", "--json",
78-
"path:"+flakeDirResolved,
79-
)
78+
cmd := command("print-dev-env", "--json")
79+
if featureflag.ImpurePrintDevEnv.Enabled() {
80+
cmd.Args = append(cmd.Args, "--impure")
81+
}
82+
cmd.Args = append(cmd.Args, "path:"+flakeDirResolved)
8083
slog.Debug("running print-dev-env cmd", "cmd", cmd)
8184
data, err = cmd.Output(ctx)
8285
if insecure, insecureErr := IsExitErrorInsecurePackage(err, "" /*pkgName*/, "" /*installable*/); insecure {

0 commit comments

Comments
 (0)