|
4 | 4 | package boxcli
|
5 | 5 |
|
6 | 6 | import (
|
7 |
| - "fmt" |
8 | 7 | "os"
|
9 | 8 |
|
10 | 9 | "github.com/fatih/color"
|
11 |
| - "github.com/mattn/go-isatty" |
12 | 10 | "github.com/samber/lo"
|
13 | 11 | "github.com/spf13/cobra"
|
14 |
| - "go.jetpack.io/devbox/internal/boxcli/usererr" |
15 | 12 | "go.jetpack.io/devbox/internal/nix"
|
16 | 13 | "go.jetpack.io/devbox/internal/ux"
|
17 | 14 | )
|
@@ -50,44 +47,8 @@ func runInstallNixCmd(cmd *cobra.Command) error {
|
50 | 47 | return nix.Install(cmd.ErrOrStderr(), nixDaemonFlagVal(cmd))
|
51 | 48 | }
|
52 | 49 |
|
53 |
| -func ensureNixInstalled(cmd *cobra.Command, args []string) error { |
54 |
| - if nix.BinaryInstalled() { |
55 |
| - return nil |
56 |
| - } |
57 |
| - if nix.DirExists() { |
58 |
| - if err := nix.SourceNixEnv(); err != nil { |
59 |
| - return err |
60 |
| - } else if nix.BinaryInstalled() { |
61 |
| - return nil |
62 |
| - } |
63 |
| - |
64 |
| - return usererr.New( |
65 |
| - "We found a /nix directory but nix binary is not in your PATH and we " + |
66 |
| - "were not able to find it in the usual locations. Your nix installation " + |
67 |
| - "might be broken. If restarting your terminal or reinstalling nix " + |
68 |
| - "doesn't work, please create an issue at " + |
69 |
| - "https://github.com/jetpack-io/devbox/issues", |
70 |
| - ) |
71 |
| - } |
72 |
| - |
73 |
| - color.Yellow("\nNix is not installed. Devbox will attempt to install it.\n\n") |
74 |
| - |
75 |
| - if isatty.IsTerminal(os.Stdout.Fd()) { |
76 |
| - color.Yellow("Press enter to continue or ctrl-c to exit.\n") |
77 |
| - fmt.Scanln() |
78 |
| - } |
79 |
| - |
80 |
| - if err := nix.Install(cmd.ErrOrStderr(), nixDaemonFlagVal(cmd)); err != nil { |
81 |
| - return err |
82 |
| - } |
83 |
| - |
84 |
| - // Source again |
85 |
| - if err := nix.SourceNixEnv(); err != nil { |
86 |
| - return err |
87 |
| - } |
88 |
| - |
89 |
| - cmd.PrintErrln("Nix installed successfully. Devbox is ready to use!") |
90 |
| - return nil |
| 50 | +func ensureNixInstalled(cmd *cobra.Command, _args []string) error { |
| 51 | + return nix.EnsureNixInstalled(cmd.ErrOrStderr(), nixDaemonFlagVal(cmd)) |
91 | 52 | }
|
92 | 53 |
|
93 | 54 | func nixDaemonFlagVal(cmd *cobra.Command) *bool {
|
|
0 commit comments