Skip to content

[glibc] Add patch-glibc patch and fix when package in binary cache #1669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/boxcli/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type addCmdFlags struct {
disablePlugin bool
platforms []string
excludePlatforms []string
patchGlibc bool
}

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

return command
}
Expand All @@ -81,5 +85,6 @@ func addCmdFunc(cmd *cobra.Command, args []string, flags addCmdFlags) error {
DisablePlugin: flags.disablePlugin,
Platforms: flags.platforms,
ExcludePlatforms: flags.excludePlatforms,
PatchGlibc: flags.patchGlibc,
})
}
15 changes: 14 additions & 1 deletion internal/devconfig/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,20 @@ func (pkgs *Packages) UnmarshalJSON(data []byte) error {
return nil
}

func (pkgs *Packages) DisablePlugin(versionedName string, v bool) error {
func (pkgs *Packages) SetPatchGLibc(versionedName string, v bool) error {
name, version := parseVersionedName(versionedName)
i := pkgs.index(name, version)
if i == -1 {
return errors.Errorf("package %s not found", versionedName)
}
if pkgs.Collection[i].PatchGlibc != v {
pkgs.Collection[i].PatchGlibc = v
pkgs.ast.setPackageBool(name, "patch_glibc", v)
}
return nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to confirm, if the packages is a []string in json, then this will convert it to a map[string] (string | object)?


func (pkgs *Packages) SetDisablePlugin(versionedName string, v bool) error {
name, version := parseVersionedName(versionedName)
i := pkgs.index(name, version)
if i == -1 {
Expand Down
4 changes: 4 additions & 0 deletions internal/devpkg/narinfo_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const BinaryCache = "https://cache.nixos.org"
// ALERT: Callers in a perf-sensitive code path should call FillNarInfoCache
// before calling this function.
func (p *Package) IsInBinaryCache() (bool, error) {
// Patched glibc packages are not in the binary cache.
if p.PatchGlibc {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be PatchGlibc && linux

or better still the PatchGlibc boolean should only be set if it is specified in the devbox.json and the current OS is linux

return false, nil
}
if eligible, err := p.isEligibleForBinaryCache(); err != nil {
return false, err
} else if !eligible {
Expand Down
4 changes: 2 additions & 2 deletions internal/devpkg/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func PackagesFromConfig(config *devconfig.Config, l lock.Locker) []*Package {
for _, cfgPkg := range config.Packages.Collection {
pkg := newPackage(cfgPkg.VersionedName(), cfgPkg.IsEnabledOnPlatform(), l)
pkg.DisablePlugin = cfgPkg.DisablePlugin
pkg.PatchGlibc = cfgPkg.PatchGlibc
pkg.PatchGlibc = cfgPkg.PatchGlibc && nix.SystemIsLinux()
result = append(result, pkg)
}
return result
Expand All @@ -127,7 +127,7 @@ func PackageFromStringWithDefaults(raw string, locker lock.Locker) *Package {
func PackageFromStringWithOptions(raw string, locker lock.Locker, opts devopt.AddOpts) *Package {
pkg := PackageFromStringWithDefaults(raw, locker)
pkg.DisablePlugin = opts.DisablePlugin
// TODO: add patchGlibc flag
pkg.PatchGlibc = opts.PatchGlibc
return pkg
}

Expand Down
1 change: 1 addition & 0 deletions internal/impl/devopt/devboxopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type AddOpts struct {
Platforms []string
ExcludePlatforms []string
DisablePlugin bool
PatchGlibc bool
}

type UpdateOpts struct {
Expand Down
8 changes: 7 additions & 1 deletion internal/impl/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ func (d *Devbox) setPackageOptions(pkgs []string, opts devopt.AddOpts) error {
d.stderr, pkg, opts.ExcludePlatforms); err != nil {
return err
}
if err := d.cfg.Packages.DisablePlugin(pkg, opts.DisablePlugin); err != nil {
if err := d.cfg.Packages.SetDisablePlugin(
pkg, opts.DisablePlugin); err != nil {
return err
}

if err := d.cfg.Packages.SetPatchGLibc(
pkg, opts.PatchGlibc); err != nil {
return err
}
}
Expand Down
4 changes: 4 additions & 0 deletions internal/nix/nix.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ func ComputeSystem() error {
return nil
}

func SystemIsLinux() bool {
return strings.Contains(System(), "linux")
}

// version is the cached output of `nix --version`.
var version = ""

Expand Down