Skip to content

Commit 8c49985

Browse files
authored
[glibc] Add patch-glibc patch and fix when package in binary cache (#1669)
## Summary * Adds new `--patch-glibc` flag * Fixes glibc feature (I think) when package is in binary cache. We were previouwly always installing the cached version instead of the patched version. ## How was it tested? * Flag was tested using `devbox add python --patch-glibc` * I'm not 100% sure how to test the patch itself, but I did verify we are creating the patch flake
1 parent 347f65b commit 8c49985

File tree

7 files changed

+37
-4
lines changed

7 files changed

+37
-4
lines changed

internal/boxcli/add.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type addCmdFlags struct {
2323
disablePlugin bool
2424
platforms []string
2525
excludePlatforms []string
26+
patchGlibc bool
2627
}
2728

2829
func addCmd() *cobra.Command {
@@ -63,6 +64,9 @@ func addCmd() *cobra.Command {
6364
command.Flags().StringSliceVarP(
6465
&flags.excludePlatforms, "exclude-platform", "e", []string{},
6566
"exclude packages from a specific platform.")
67+
command.Flags().BoolVar(
68+
&flags.patchGlibc, "patch-glibc", false,
69+
"patch any ELF binaries to use the latest glibc version in nixpkgs")
6670

6771
return command
6872
}
@@ -81,5 +85,6 @@ func addCmdFunc(cmd *cobra.Command, args []string, flags addCmdFlags) error {
8185
DisablePlugin: flags.disablePlugin,
8286
Platforms: flags.platforms,
8387
ExcludePlatforms: flags.excludePlatforms,
88+
PatchGlibc: flags.patchGlibc,
8489
})
8590
}

internal/devconfig/packages.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,20 @@ func (pkgs *Packages) UnmarshalJSON(data []byte) error {
177177
return nil
178178
}
179179

180-
func (pkgs *Packages) DisablePlugin(versionedName string, v bool) error {
180+
func (pkgs *Packages) SetPatchGLibc(versionedName string, v bool) error {
181+
name, version := parseVersionedName(versionedName)
182+
i := pkgs.index(name, version)
183+
if i == -1 {
184+
return errors.Errorf("package %s not found", versionedName)
185+
}
186+
if pkgs.Collection[i].PatchGlibc != v {
187+
pkgs.Collection[i].PatchGlibc = v
188+
pkgs.ast.setPackageBool(name, "patch_glibc", v)
189+
}
190+
return nil
191+
}
192+
193+
func (pkgs *Packages) SetDisablePlugin(versionedName string, v bool) error {
181194
name, version := parseVersionedName(versionedName)
182195
i := pkgs.index(name, version)
183196
if i == -1 {

internal/devpkg/narinfo_cache.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ const BinaryCache = "https://cache.nixos.org"
2525
// ALERT: Callers in a perf-sensitive code path should call FillNarInfoCache
2626
// before calling this function.
2727
func (p *Package) IsInBinaryCache() (bool, error) {
28+
// Patched glibc packages are not in the binary cache.
29+
if p.PatchGlibc {
30+
return false, nil
31+
}
2832
if eligible, err := p.isEligibleForBinaryCache(); err != nil {
2933
return false, err
3034
} else if !eligible {

internal/devpkg/package.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func PackagesFromConfig(config *devconfig.Config, l lock.Locker) []*Package {
114114
for _, cfgPkg := range config.Packages.Collection {
115115
pkg := newPackage(cfgPkg.VersionedName(), cfgPkg.IsEnabledOnPlatform(), l)
116116
pkg.DisablePlugin = cfgPkg.DisablePlugin
117-
pkg.PatchGlibc = cfgPkg.PatchGlibc
117+
pkg.PatchGlibc = cfgPkg.PatchGlibc && nix.SystemIsLinux()
118118
result = append(result, pkg)
119119
}
120120
return result
@@ -127,7 +127,7 @@ func PackageFromStringWithDefaults(raw string, locker lock.Locker) *Package {
127127
func PackageFromStringWithOptions(raw string, locker lock.Locker, opts devopt.AddOpts) *Package {
128128
pkg := PackageFromStringWithDefaults(raw, locker)
129129
pkg.DisablePlugin = opts.DisablePlugin
130-
// TODO: add patchGlibc flag
130+
pkg.PatchGlibc = opts.PatchGlibc
131131
return pkg
132132
}
133133

internal/impl/devopt/devboxopts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type AddOpts struct {
4242
Platforms []string
4343
ExcludePlatforms []string
4444
DisablePlugin bool
45+
PatchGlibc bool
4546
}
4647

4748
type UpdateOpts struct {

internal/impl/packages.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ func (d *Devbox) setPackageOptions(pkgs []string, opts devopt.AddOpts) error {
124124
d.stderr, pkg, opts.ExcludePlatforms); err != nil {
125125
return err
126126
}
127-
if err := d.cfg.Packages.DisablePlugin(pkg, opts.DisablePlugin); err != nil {
127+
if err := d.cfg.Packages.SetDisablePlugin(
128+
pkg, opts.DisablePlugin); err != nil {
129+
return err
130+
}
131+
132+
if err := d.cfg.Packages.SetPatchGLibc(
133+
pkg, opts.PatchGlibc); err != nil {
128134
return err
129135
}
130136
}

internal/nix/nix.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ func ComputeSystem() error {
157157
return nil
158158
}
159159

160+
func SystemIsLinux() bool {
161+
return strings.Contains(System(), "linux")
162+
}
163+
160164
// version is the cached output of `nix --version`.
161165
var version = ""
162166

0 commit comments

Comments
 (0)