|
4 | 4 | package devbox
|
5 | 5 |
|
6 | 6 | import (
|
7 |
| - "fmt" |
8 | 7 | "io/fs"
|
9 | 8 | "os"
|
10 | 9 | "path/filepath"
|
11 |
| - "strings" |
12 | 10 |
|
13 | 11 | "github.com/pkg/errors"
|
14 |
| - "go.jetpack.io/devbox/internal/debug" |
15 |
| - "go.jetpack.io/devbox/internal/xdg" |
16 | 12 | )
|
17 | 13 |
|
18 |
| -// findNixInPATH looks for locations in PATH which nix might exist and |
19 |
| -// it returns a slice containing all paths that might contain nix. |
20 |
| -// For single-user, and multi-user installation there are default locations |
21 |
| -// unless XDG_* env variables are set. So we look for nix in 3 locations |
22 |
| -// to see if any of those exist in path. |
23 |
| -func findNixInPATH(env map[string]string) ([]string, error) { |
24 |
| - defaultSingleUserNixBin := fmt.Sprintf("%s/.nix-profile/bin", env["HOME"]) |
25 |
| - defaultMultiUserNixBin := "/nix/var/nix/profiles/default/bin" |
26 |
| - xdgNixBin := xdg.StateSubpath("/nix/profile/bin") |
27 |
| - pathElements := strings.Split(env["PATH"], ":") |
28 |
| - debug.Log("path elements: %v", pathElements) |
29 |
| - nixBinsInPath := []string{} |
30 |
| - for _, el := range pathElements { |
31 |
| - if el == xdgNixBin || |
32 |
| - el == defaultSingleUserNixBin || |
33 |
| - el == defaultMultiUserNixBin { |
34 |
| - nixBinsInPath = append(nixBinsInPath, el) |
35 |
| - } |
36 |
| - } |
37 |
| - |
38 |
| - if len(nixBinsInPath) == 0 { |
39 |
| - // did not find nix executable in PATH, return error |
40 |
| - return nil, errors.New("could not find any nix executable in PATH. Make sure Nix is installed and in PATH, then try again") |
41 |
| - } |
42 |
| - return nixBinsInPath, nil |
43 |
| -} |
44 |
| - |
45 | 14 | // Creates a symlink for devbox in .devbox/bin
|
46 | 15 | // so that devbox can be available inside a pure shell
|
47 | 16 | func createDevboxSymlink(d *Devbox) error {
|
|
0 commit comments