Skip to content

rustplatform.cargoSetupHook: force common system libs - #537108

Merged
GrimmTheShrimp merged 26 commits into
NixOS:stagingfrom
RossSmyth:rustplatform.cargosetuphook-force-system-libs/rknyqyuusosu
Oct 14, 2026
Merged

GrimmTheShrimp merged 26 commits into
NixOS:stagingfrom
RossSmyth:rustplatform.cargosetuphook-force-system-libs/rknyqyuusosu

Conversation

@RossSmyth

@RossSmyth RossSmyth commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Things done

We want to use system libraries as often as possible. This forces certain common libraries to fail to build if in the tree, and not using system libraries. This is done by setting environement variables that either:

  1. Force to use system libs
  2. Set directories to dummy sentinels

The first is generally easy, as probing usually occurs via pkg-config, so you just do the same thing as any other package: add pkg-config to nativeBuildInputs, then add your library to buildInputs.

The second is slightly weirder as it is ad-hoc per Rust crate. You need to set vars for lib/include/src for each package in the environment with whatever variable it wants.

I selected the libraries by going on crates.io, searching "-sys", and going through the first few pages.

I will add a release note before merging as I don't really want to deal with release-notes through the review cycle.

@RossSmyth
RossSmyth force-pushed the rustplatform.cargosetuphook-force-system-libs/rknyqyuusosu branch from 83d32b8 to 4d064d2 Compare June 30, 2026 15:53
nixpkgs-branch-check[bot]

This comment was marked as outdated.

@RossSmyth
RossSmyth force-pushed the rustplatform.cargosetuphook-force-system-libs/rknyqyuusosu branch from 4d064d2 to ee1be6d Compare June 30, 2026 15:59
@RossSmyth
RossSmyth changed the base branch from master to staging June 30, 2026 15:59
@nixpkgs-ci nixpkgs-ci Bot closed this Jun 30, 2026
@nixpkgs-ci nixpkgs-ci Bot reopened this Jun 30, 2026
@RossSmyth

Copy link
Copy Markdown
Contributor Author

Looks like we do not document the hook variables anywhere, that is unfortunate.

@nixpkgs-branch-check
nixpkgs-branch-check Bot dismissed their stale review June 30, 2026 16:09

Review dismissed automatically

@nixpkgs-ci
nixpkgs-ci Bot requested a review from a team June 30, 2026 16:12
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. 6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. labels Jun 30, 2026

@SandaruKasa SandaruKasa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds reasonable

@winterqt

Copy link
Copy Markdown
Member

I think my only concern is dealing with the fallout. I might try and do some form of spot check of major non-leaf packages that blow up because of this.

@RossSmyth

Copy link
Copy Markdown
Contributor Author

Yeah will need a coordinated move to merge

@nixpkgs-ci nixpkgs-ci Bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jun 30, 2026
@figsoda

figsoda commented Jun 30, 2026

Copy link
Copy Markdown
Member

a few ones from nix-init's list

  • LIBGIT2_NO_VENDOR from libgit2-sys
  • SODIUM_USE_PKG_CONFIG from libsodium-sys and libsodium-sys-stable
  • RUSTONIG_SYSTEM_LIBONIG from onig_sys

this is gonna break a lot of things, we should probably check the lock files (or let cargo resolve the features to reduce false positives) and add the missing dependencies automatically, which should cover most of the use cases

@emilazy

emilazy commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

That would be IFD.

Edit: Oh, unless you mean as an automated treewide?

@winterqt

Copy link
Copy Markdown
Member

I’m kind of fine with letting leaf packages break if we do cleanups during the cycle for popular stuff and just let maintainers pick up the rest as it trickles down to unstable.

@figsoda

figsoda commented Jun 30, 2026

Copy link
Copy Markdown
Member

Edit: Oh, unless you mean as an automated treewide?

yeah, kinda like when we did the treewide hash update

@RossSmyth
RossSmyth force-pushed the rustplatform.cargosetuphook-force-system-libs/rknyqyuusosu branch from ee1be6d to fe4989b Compare June 30, 2026 23:38
@RossSmyth

Copy link
Copy Markdown
Contributor Author

Went through the defaultCrateOverrides for crate2nix and added their info. Most are just adding libs that the build will fail without, some were not.

@RossSmyth
RossSmyth force-pushed the rustplatform.cargosetuphook-force-system-libs/rknyqyuusosu branch from fe4989b to 69a853b Compare July 30, 2026 14:14
@RossSmyth

Copy link
Copy Markdown
Contributor Author

Is there any actual interest in this PR? I can organize merging it to staging, but I'm not going to even try if I have to fight the whole way.

@nyabinary

Copy link
Copy Markdown
Contributor

Is there any actual interest in this PR? I can organize merging it to staging, but I'm not going to even try if I have to fight the whole way.

It def would be a nice to have for me personally

@ethancedwards8

Copy link
Copy Markdown
Member

Is there any actual interest in this PR? I can organize merging it to staging, but I'm not going to even try if I have to fight the whole way.

I am def. interested in this and am more than willing to help with the breakage fallout.

@RossSmyth

RossSmyth commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Okay, that's two + one more on Matrix volunteering. I'll see if I can test this properly. I was able to build an ISO with this PR, next I'd like to find a package that fails with this PR to make sure it actually does the one thing it should do.

Don't expect too much this week or next as I am currently engrossed in a video game. But I will get to it.

@brady444

Copy link
Copy Markdown

@RossSmyth

We want to use system libraries as often as possible.

Why? Just curious

@RossSmyth

Copy link
Copy Markdown
Contributor Author

No matter what happens, the crate will link to aws-lc and the others. The difference is that before this patch it will statically link to a pinned vendored version that is downloaded with the crate. This means that if zstd, aws-lc, or the others have a security vulnerability, the crate will continue using the pinned version from several months or years ago. This changes it to link to our libraries that are updated.

@whispersofthedawn

whispersofthedawn commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

We want to use system libraries as often as possible.

Why? Just curious

there are a couple reasons, but the single most prominent one is that it allows us to centralize handling of updates. if every package vendored its own copy of a critical package like zlib, when a security update to zlib is released (like happened just last week!), we now have to track down every version of zlib in every package and update it (hint: this won't happen. we don't have the manpower or the tooling for that). in rust packages, that means either convincing upstreams to cut a release or patch lockfiles ourselves. it's much, much easier for us update zlib in one (1) place, and have that immediately benefit every other package in nixpkgs. you also get some smaller benefits, like avoiding building a copy of zlib in every separate package or gaining e.g. performance improvements when upstreams cut a new release.

it also sort of ties into the same reason nixpkgs is "one thing", as opposed to separate distributions for each individual package. we generally aim to provide a cohesive package set where everything uses our versions of packages, and we tie them together so that we can handle them all centrally. the usage of every package vendoring its own lockfiles and pinned rust dependencies is actually a compromise here for the sake of practicality; if we were to use the typical system dependency model, we'd ship every rust crate as part of nixpkgs and update them separately. that's not really viable right now, but for system libraries, nixpkgs is really good at shipping those (given, you know, it's our entire job), and so it makes sense to do it for those.

@Pandapip1

Pandapip1 commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

It also allows overlays to affect packages that would otherwise not be affected. For example, I have a bunch of VLC patches that fix bluetooth headphone playback being out of tune and a few other minor annoyances. I don't have to use VLC to get the benefit of that, any other libvlc-based player benefits from those patches. However, if a rust package vendored its own libvlc, it would still have the 'bluetooth headphones play N cents sharp depending on the file type' bug and drive me bananas.

It also helps make it clear what dependencies a package actually uses, for e.g. when auditing the dependency graph of a package.

Finally, for dynamically linked packages, it saves a little bit of disk space by not duplicating the library contents inside the binary.

@Deric-W Deric-W mentioned this pull request Nov 15, 2026
4 of 13 tasks
@iedame iedame mentioned this pull request Nov 15, 2026
5 of 13 tasks
@kira-bruneau kira-bruneau mentioned this pull request Nov 16, 2026
4 of 13 tasks
@rntpts rntpts mentioned this pull request Nov 27, 2026
3 of 13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nodejs Node.js is a free, open-source, cross-platform JavaScript runtime environment 6.topic: python Python is a high-level, general-purpose programming language. 6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. 12.approvals: 3+ This PR was reviewed and approved by three or more persons. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages.

Projects

Status: ✅ Done
Status: Done

Development

Successfully merging this pull request may close these issues.

Enable OPENSSL_NO_VENDOR by default for rustPlatform (or in-tree rust packages?)