@@ -10,19 +10,36 @@ import (
10
10
"github.com/MakeNowJust/heredoc/v2"
11
11
"github.com/hashicorp/go-envparse"
12
12
"github.com/pkg/errors"
13
+ "go.jetpack.io/devbox/internal/boxcli/usererr"
14
+ "go.jetpack.io/devbox/internal/xdg"
13
15
)
14
16
17
+ func nixLinks () []string {
18
+ return []string {
19
+ "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" ,
20
+ filepath .Join (os .Getenv ("HOME" ), ".nix-profile/etc/profile.d/nix.sh" ),
21
+ // logic introduced in https://github.com/NixOS/nix/pull/5588/files
22
+ xdg .StateSubpath ("nix/profile/etc/profile.d/nix.sh" ),
23
+ }
24
+ }
25
+
15
26
func SourceNixEnv () error {
16
27
// if command is not in path, the source the nix startup files and hopefully
17
28
// the command will be found. (we should still check that nix is actually
18
29
// installed before we get here)
19
- srcFile := "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"
20
- // if global (multi-user) daemon file is missing, try getting the single user
21
- // file.
22
- if _ , err := os .Stat (srcFile ); os .IsNotExist (err ) {
23
- srcFile = filepath .Join (
24
- os .Getenv ("HOME" ),
25
- "/.nix-profile/etc/profile.d/nix.sh" ,
30
+ srcFile := ""
31
+ for _ , f := range nixLinks () {
32
+ if _ , err := os .Stat (f ); err == nil {
33
+ srcFile = f
34
+ break
35
+ }
36
+ }
37
+
38
+ if srcFile == "" {
39
+ return usererr .New (
40
+ "Unable to find nix startup file. If /nix directory exists it's " +
41
+ "possible the installation did not complete successfully. Follow " +
42
+ "instructions at https://nixos.org/download.html for manual install." ,
26
43
)
27
44
}
28
45
0 commit comments