Skip to content

Commit 4d9db7d

Browse files
authored
[nix] ensure nix version is >= 2.12 (#1700)
## Summary Ensures that the nix used is >= 2.12 which is the minimum version we support. Our CICD tests run this version, and I believe so does @mohsenari. I considered renaming the function to `ensureSupportedNixInstalled` but decided against it. The current name is good enough, given the function's scope and location in the package. ## How was it tested? ran `devbox shell` which results in this function being called. Toggled the condition to trigger the error to verify it prints as we want.
1 parent 3f955d5 commit 4d9db7d

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

internal/boxcli/setup.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
package boxcli
55

66
import (
7+
"fmt"
78
"os"
89

910
"github.com/samber/lo"
1011
"github.com/spf13/cobra"
11-
12+
"go.jetpack.io/devbox/internal/boxcli/usererr"
1213
"go.jetpack.io/devbox/internal/nix"
1314
"go.jetpack.io/devbox/internal/ux"
15+
"go.jetpack.io/devbox/internal/vercheck"
1416
)
1517

1618
const nixDaemonFlag = "daemon"
@@ -47,8 +49,22 @@ func runInstallNixCmd(cmd *cobra.Command) error {
4749
return nix.Install(cmd.ErrOrStderr(), nixDaemonFlagVal(cmd)())
4850
}
4951

52+
// ensureNixInstalled verifies that nix is installed and that it is of a supported version
5053
func ensureNixInstalled(cmd *cobra.Command, _args []string) error {
51-
return nix.EnsureNixInstalled(cmd.ErrOrStderr(), nixDaemonFlagVal(cmd))
54+
if err := nix.EnsureNixInstalled(cmd.ErrOrStderr(), nixDaemonFlagVal(cmd)); err != nil {
55+
return err
56+
}
57+
58+
ver, err := nix.Version()
59+
if err != nil {
60+
return fmt.Errorf("failed to get nix version: %w", err)
61+
}
62+
63+
// ensure minimum nix version installed
64+
if vercheck.SemverCompare(ver, "2.12.0") < 0 {
65+
return usererr.New("Devbox requires nix of version >= 2.12. Your version is %s. Please upgrade nix and try again.\n", ver)
66+
}
67+
return nil
5268
}
5369

5470
// We return a closure to avoid printing the warning every time and just

0 commit comments

Comments
 (0)