diff --git a/internal/boxcli/setup.go b/internal/boxcli/setup.go index 875343aad76..507607ef67d 100644 --- a/internal/boxcli/setup.go +++ b/internal/boxcli/setup.go @@ -4,13 +4,15 @@ package boxcli import ( + "fmt" "os" "github.com/samber/lo" "github.com/spf13/cobra" - + "go.jetpack.io/devbox/internal/boxcli/usererr" "go.jetpack.io/devbox/internal/nix" "go.jetpack.io/devbox/internal/ux" + "go.jetpack.io/devbox/internal/vercheck" ) const nixDaemonFlag = "daemon" @@ -47,8 +49,22 @@ func runInstallNixCmd(cmd *cobra.Command) error { return nix.Install(cmd.ErrOrStderr(), nixDaemonFlagVal(cmd)()) } +// ensureNixInstalled verifies that nix is installed and that it is of a supported version func ensureNixInstalled(cmd *cobra.Command, _args []string) error { - return nix.EnsureNixInstalled(cmd.ErrOrStderr(), nixDaemonFlagVal(cmd)) + if err := nix.EnsureNixInstalled(cmd.ErrOrStderr(), nixDaemonFlagVal(cmd)); err != nil { + return err + } + + ver, err := nix.Version() + if err != nil { + return fmt.Errorf("failed to get nix version: %w", err) + } + + // ensure minimum nix version installed + if vercheck.SemverCompare(ver, "2.12.0") < 0 { + return usererr.New("Devbox requires nix of version >= 2.12. Your version is %s. Please upgrade nix and try again.\n", ver) + } + return nil } // We return a closure to avoid printing the warning every time and just