Skip to content

Commit c628777

Browse files
authored
devbox: add nix installation check to all commands (#2649)
## Summary devbox: add nix installation check to all commands ## How was it tested? go build devbox shell ## Is this change backwards-compatible? Yes
1 parent 20f429f commit c628777

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

boxcli/root.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ package boxcli
55

66
import (
77
"context"
8+
"errors"
89
"os"
10+
"os/exec"
911

1012
"github.com/spf13/cobra"
1113
)
@@ -17,6 +19,13 @@ func RootCmd() *cobra.Command {
1719
// Don't display 'usage' on application errors.
1820
cmd.SilenceUsage = true
1921
},
22+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
23+
_, err := exec.LookPath("nix-shell")
24+
if err != nil {
25+
return errors.New("Could not find nix in your PATH\nInstall nix by following the instructions at https://nixos.org/download.html and make sure you've set up your PATH correctly.")
26+
}
27+
return nil
28+
},
2029
RunE: func(cmd *cobra.Command, args []string) error {
2130
return cmd.Help()
2231
},

nix/nix.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@ package nix
66
import (
77
"bytes"
88
"encoding/json"
9-
"errors"
109
"fmt"
1110
"os"
1211
"os/exec"
1312
"strings"
1413
)
1514

1615
func Shell(path string) error {
17-
_, err := exec.LookPath("nix-shell")
18-
if err != nil {
19-
return errors.New("Could not find nix in your PATH\nInstall nix by following the instructions at https://nixos.org/download.html and make sure you've set up your PATH correctly.")
20-
}
2116
cmd := exec.Command("nix-shell", path)
2217
// Default to the shell already being used.
2318
shell := os.Getenv("SHELL")

0 commit comments

Comments
 (0)