diff --git a/internal/boxcli/featureflag/impure_print_dev_env.go b/internal/boxcli/featureflag/impure_print_dev_env.go new file mode 100644 index 00000000000..fc3744036aa --- /dev/null +++ b/internal/boxcli/featureflag/impure_print_dev_env.go @@ -0,0 +1,12 @@ +// Copyright 2024 Jetify Inc. and contributors. All rights reserved. +// Use of this source code is governed by the license in the LICENSE file. + +package featureflag + +// ImpurePrintDevEnv controls whether the `devbox print-dev-env` command +// will be called with the `--impure` flag. +// Using the `--impure` flag will have two consequences: +// 1. All environment variables will be passed to nix, this will enable +// the usage of flakes that rely on environment variables. +// 2. It will disable nix caching, making the command slower. +var ImpurePrintDevEnv = disable("IMPURE_PRINT_DEV_ENV") diff --git a/internal/nix/nix.go b/internal/nix/nix.go index 7aed7ae9899..8104354f0eb 100644 --- a/internal/nix/nix.go +++ b/internal/nix/nix.go @@ -20,6 +20,7 @@ import ( "time" "github.com/pkg/errors" + "go.jetpack.io/devbox/internal/boxcli/featureflag" "go.jetpack.io/devbox/internal/boxcli/usererr" "go.jetpack.io/devbox/internal/redact" "golang.org/x/mod/semver" @@ -74,9 +75,11 @@ func (*Nix) PrintDevEnv(ctx context.Context, args *PrintDevEnvArgs) (*PrintDevEn } if len(data) == 0 { - cmd := command("print-dev-env", "--json", - "path:"+flakeDirResolved, - ) + cmd := command("print-dev-env", "--json") + if featureflag.ImpurePrintDevEnv.Enabled() { + cmd.Args = append(cmd.Args, "--impure") + } + cmd.Args = append(cmd.Args, "path:"+flakeDirResolved) slog.Debug("running print-dev-env cmd", "cmd", cmd) data, err = cmd.Output(ctx) if insecure, insecureErr := IsExitErrorInsecurePackage(err, "" /*pkgName*/, "" /*installable*/); insecure {