4
4
package devpkg
5
5
6
6
import (
7
+ "cmp"
7
8
"context"
8
9
"fmt"
9
10
"io"
11
+ "log/slog"
10
12
"path/filepath"
11
13
"regexp"
12
14
"strings"
@@ -81,10 +83,9 @@ type Package struct {
81
83
// Outputs is a list of outputs to build from the package's derivation.
82
84
outputs outputs
83
85
84
- // patch applies a function to the package's derivation that
85
- // patches any ELF binaries to use the latest version of nixpkgs#glibc.
86
- // It's a function to allow deferring nix System call until it's needed.
87
- patch func () bool
86
+ // Patch controls if Devbox environments will do additional patching to
87
+ // address known issues with the package.
88
+ Patch bool
88
89
89
90
// AllowInsecure are a list of nix packages that are whitelisted to be
90
91
// installed even if they are marked as insecure.
@@ -110,7 +111,7 @@ func PackagesFromConfig(packages []configfile.Package, l lock.Locker) []*Package
110
111
for _ , cfgPkg := range packages {
111
112
pkg := newPackage (cfgPkg .VersionedName (), cfgPkg .IsEnabledOnPlatform , l )
112
113
pkg .DisablePlugin = cfgPkg .DisablePlugin
113
- pkg .patch = patchGlibcFunc (pkg .CanonicalName (), cfgPkg .Patch )
114
+ pkg .Patch = pkgNeedsPatch (pkg .CanonicalName (), cfgPkg .Patch )
114
115
pkg .outputs .selectedNames = lo .Uniq (append (pkg .outputs .selectedNames , cfgPkg .Outputs ... ))
115
116
pkg .AllowInsecure = cfgPkg .AllowInsecure
116
117
result = append (result , pkg )
@@ -125,7 +126,7 @@ func PackageFromStringWithDefaults(raw string, locker lock.Locker) *Package {
125
126
func PackageFromStringWithOptions (raw string , locker lock.Locker , opts devopt.AddOpts ) * Package {
126
127
pkg := PackageFromStringWithDefaults (raw , locker )
127
128
pkg .DisablePlugin = opts .DisablePlugin
128
- pkg .patch = patchGlibcFunc (pkg .CanonicalName (), configfile .PatchMode (opts .Patch ))
129
+ pkg .Patch = pkgNeedsPatch (pkg .CanonicalName (), configfile .PatchMode (opts .Patch ))
129
130
pkg .outputs .selectedNames = lo .Uniq (append (pkg .outputs .selectedNames , opts .Outputs ... ))
130
131
pkg .AllowInsecure = opts .AllowInsecure
131
132
return pkg
@@ -155,6 +156,7 @@ func newPackage(raw string, isInstallable func() bool, locker lock.Locker) *Pack
155
156
pkg .resolve = sync .OnceValue (func () error { return nil })
156
157
pkg .setInstallable (parsed , locker .ProjectDir ())
157
158
pkg .outputs = outputs {selectedNames : strings .Split (parsed .Outputs , "," )}
159
+ pkg .Patch = pkgNeedsPatch (pkg .CanonicalName (), configfile .PatchAuto )
158
160
return pkg
159
161
}
160
162
@@ -177,27 +179,31 @@ func resolve(pkg *Package) error {
177
179
return nil
178
180
}
179
181
180
- func patchGlibcFunc (canonicalName string , mode configfile.PatchMode ) func () bool {
181
- return sync .OnceValue (func () (patch bool ) {
182
- switch mode {
183
- case configfile .PatchAuto :
184
- patch = canonicalName == "python"
185
- case configfile .PatchAlways :
186
- patch = true
187
- case configfile .PatchNever :
188
- patch = false
189
- }
190
- return patch
191
- })
192
- }
193
-
194
182
func (p * Package ) setInstallable (i flake.Installable , projectDir string ) {
195
183
if i .Ref .Type == flake .TypePath && ! filepath .IsAbs (i .Ref .Path ) {
196
184
i .Ref .Path = filepath .Join (projectDir , i .Ref .Path )
197
185
}
198
186
p .installable = i
199
187
}
200
188
189
+ func pkgNeedsPatch (canonicalName string , mode configfile.PatchMode ) (patch bool ) {
190
+ mode = cmp .Or (mode , configfile .PatchAuto )
191
+ switch mode {
192
+ case configfile .PatchAuto :
193
+ patch = canonicalName == "python"
194
+ case configfile .PatchAlways :
195
+ patch = true
196
+ case configfile .PatchNever :
197
+ patch = false
198
+ }
199
+ if patch {
200
+ slog .Debug ("package needs patching" , "pkg" , canonicalName , "mode" , mode )
201
+ } else {
202
+ slog .Debug ("package doesn't need patching" , "pkg" , canonicalName , "mode" , mode )
203
+ }
204
+ return patch
205
+ }
206
+
201
207
var inputNameRegex = regexp .MustCompile ("[^a-zA-Z0-9-]+" )
202
208
203
209
// FlakeInputName generates a name for the input that will be used in the
@@ -249,10 +255,6 @@ func (p *Package) IsInstallable() bool {
249
255
return p .isInstallable ()
250
256
}
251
257
252
- func (p * Package ) PatchGlibc () bool {
253
- return p .patch != nil && p .patch ()
254
- }
255
-
256
258
// Installables for this package. Installables is a nix concept defined here:
257
259
// https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html#installables
258
260
func (p * Package ) Installables () ([]string , error ) {
0 commit comments