From 822511ad158885b42940279039e22035517647b0 Mon Sep 17 00:00:00 2001 From: Lucille Hua Date: Fri, 26 Aug 2022 11:12:39 -0700 Subject: [PATCH] Add nix package manager detector and error if not installed (#2641) ## Summary Check if nix package manager is installed before calling nix ## How was it tested? `go build -o devbox cmd/devbox/main.go` `devbox shell` ## Is this change backwards-compatible? Yes --- nix/nix.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nix/nix.go b/nix/nix.go index 06a19352b7e..e2289688016 100644 --- a/nix/nix.go +++ b/nix/nix.go @@ -6,6 +6,7 @@ package nix import ( "bytes" "encoding/json" + "errors" "fmt" "os" "os/exec" @@ -13,6 +14,10 @@ import ( ) func Shell(path string) error { + _, err := exec.LookPath("nix-shell") + if err != nil { + 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.") + } cmd := exec.Command("nix-shell", path) // Default to the shell already being used. shell := os.Getenv("SHELL")