Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions internal/boxcli/featureflag/impure_print_dev_env.go
Original file line number Diff line number Diff line change
@@ -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")
7 changes: 6 additions & 1 deletion internal/nix/nix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -74,7 +75,11 @@ func (*Nix) PrintDevEnv(ctx context.Context, args *PrintDevEnvArgs) (*PrintDevEn
}

if len(data) == 0 {
cmd := command("print-dev-env", "--json",
optionalImpureFlag := ""
if featureflag.ImpurePrintDevEnv.Enabled() {
optionalImpureFlag = "--impure"
}
cmd := command("print-dev-env", "--json", optionalImpureFlag,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do the following steps, then I get an error here:

# build binary in dist/devbox
 % devbox run build
 
 # clear local state
 % rm -rf .devbox
 
 # install the devbox-repo's own packages
 % dist/devbox install
Info: Ensuring packages are installed.
✓ Computed the Devbox environment.
Error: nix: command error: nix --extra-experimental-features ca-derivations --option experimental-features 'nix-command flakes fetch-closure' print-dev-env --json  path:/Users/savil/code/jetpack/devbox/.devbox/gen/flake: unexpected argument 'path:/Users/savil/code/jetpack/devbox/.devbox/gen/flake': exit code 1

Error: There was an internal error. Run with DEVBOX_DEBUG=1 for a detailed error message, and consider reporting it at https://github.com/jetify-com/devbox/issues

I think the issue is with the empty argument.

I think you could do:

		cmd := command("print-dev-env", "--json")
		if featureflag.ImpurePrintDevEnv.Enabled() {
			cmd.Args = append(cmd.Args, "--impure")
		}
		cmd.Args = append(cmd.Args, "path:"+flakeDirResolved)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, I thought I had tested it without the feature flag active.

Thanks for spotting this, I have pushed a fix following your suggestion.

"path:"+flakeDirResolved,
)
slog.Debug("running print-dev-env cmd", "cmd", cmd)
Expand Down
Loading