@@ -17,15 +17,14 @@ import (
17
17
"text/template"
18
18
19
19
"github.com/pkg/errors"
20
+ "go.jetpack.io/devbox/internal/boxcli/featureflag"
20
21
"go.jetpack.io/devbox/internal/cuecfg"
21
22
"go.jetpack.io/devbox/internal/debug"
22
23
)
23
24
24
25
//go:embed tmpl/*
25
26
var tmplFS embed.FS
26
27
27
- var shellFiles = []string {"shell.nix" }
28
-
29
28
// GenerateForPrintEnv will create all the files necessary for processing
30
29
// devbox.PrintEnv, which is the core function from which devbox shell/run/direnv
31
30
// functionality is derived.
@@ -39,15 +38,14 @@ func GenerateForPrintEnv(ctx context.Context, devbox devboxer) error {
39
38
40
39
outPath := genPath (devbox )
41
40
42
- for _ , file := range shellFiles {
43
- err := writeFromTemplate (outPath , plan , file )
44
- if err != nil {
45
- return errors .WithStack (err )
46
- }
41
+ // Preserving shell.nix to avoid breaking old-style .envrc users
42
+ err = writeFromTemplate (outPath , plan , "shell.nix" , "shell.nix" )
43
+ if err != nil {
44
+ return errors .WithStack (err )
47
45
}
48
46
49
47
// Gitignore file is added to the .devbox directory
50
- err = writeFromTemplate (filepath .Join (devbox .ProjectDir (), ".devbox" ), plan , ".gitignore" )
48
+ err = writeFromTemplate (filepath .Join (devbox .ProjectDir (), ".devbox" ), plan , ".gitignore" , ".gitignore" )
51
49
if err != nil {
52
50
return errors .WithStack (err )
53
51
}
69
67
tmplOldBuf = bytes .NewBuffer (make ([]byte , 0 , 4096 ))
70
68
)
71
69
72
- func writeFromTemplate (path string , plan any , tmplName string ) error {
70
+ func writeFromTemplate (path string , plan any , tmplName string , generatedName string ) error {
73
71
tmplKey := tmplName + ".tmpl"
74
72
tmpl := tmplCache [tmplKey ]
75
73
if tmpl == nil {
@@ -93,7 +91,7 @@ func writeFromTemplate(path string, plan any, tmplName string) error {
93
91
// changed. Blindly overwriting the file could invalidate Nix's cache
94
92
// every time, slowing down evaluation considerably.
95
93
var (
96
- outPath = filepath .Join (path , tmplName )
94
+ outPath = filepath .Join (path , generatedName )
97
95
flag = os .O_RDWR | os .O_CREATE
98
96
perm = fs .FileMode (0644 )
99
97
)
@@ -150,7 +148,11 @@ var templateFuncs = template.FuncMap{
150
148
151
149
func makeFlakeFile (d devboxer , outPath string , plan * flakePlan ) error {
152
150
flakeDir := FlakePath (d )
153
- err := writeFromTemplate (flakeDir , plan , "flake.nix" )
151
+ templateName := "flake.nix"
152
+ if featureflag .RemoveNixpkgs .Enabled () {
153
+ templateName = "flake_remove_nixpkgs.nix"
154
+ }
155
+ err := writeFromTemplate (flakeDir , plan , templateName , "flake.nix" )
154
156
if err != nil {
155
157
return errors .WithStack (err )
156
158
}
0 commit comments