Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nix] ensure nix version is >= 2.12 #1700

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Changes from all 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
20 changes: 18 additions & 2 deletions internal/boxcli/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Loading