Skip to content
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

{buildRustCrate, defaultCrateOverrides}: remove #373744

Closed
wants to merge 3 commits into from

Conversation

niklaskorz
Copy link
Contributor

@niklaskorz niklaskorz commented Jan 14, 2025

Motivation and historical background

The buildRustCrate helper was introduced in 2017 by 5a0d954 for the purpose of allowing Rust packages created through carnix to be included in nixpkgs.
Similar to crate2nix, carnix generated a rather large Nix expression Cargo.nix from a cargo lockfile.

As carnix has been unmaintained since 2019, @figsoda removed it in #202394.
Ever since, buildRustCrate has been left in a state where it was exposed by nixpkgs, but nothing inside nixpkgs depended on it.
The tests for buildRustCrate were previously maintained by @andir, but have been left without a maintainer since 31e5b8d.

It is unlikely that packages using buildRustCrate would ever be allowed inside nixpkgs again, partially due to the size of such generated Cargo.nix expressions.
In fact, nixpkgs is currently in progress of removing all occurences of Cargo.lock, motivated by @Atemu in #327063 and enabled by the @TomaSajt with the recently introduced rustPlatform.fetchCargoVendor in #349360.

Considerations against removal

It is noteworthy that buildRustCrate is not without maintenance, seeing a few changes and improvements per year.
A popular solution for packaging Rust outside nixpkgs that depends on buildRustCrate is crate2nix, which allows building and caching every crate in its own derivation.
crate2nix's own docs state:

Since crate2nix heavily depends on buildRustCrate in nixpkgs, it makes
sense to hack on them together.

To be able to provide pull requests, you probably want to fork
nixpkgs first. Once you have done that,
clone that fork into some local directory (separate from crate2nix).

In this regard, it may be in crate2nix's own interest to continue maintenance of buildRustCrate inside their own repository.

Furthermore, there are ongoing discussions initiated by @emilazy in #333702 to package Rust crates separately, possibly encouraging leaving buildRustCrate in tree in case it will be needed to implement such a Rust package set.
However, since the introduction of fetchCargoVendor, the urgency of such a package set seems to have shrunk.

Required actions if this were to be merged

While buildRustCrate is not needed by nixpkgs anymore, it still is a vital part of the Nix Rust community outside nixpkgs, in particular because of the popularity of crate2nix.
It should either be moved to a shared repository inside https://github.com/nix-community/ or become a part of crate2nix itself.

Ping for other maintainers involved in buildRustCrate

(this list may be non-exhaustive)

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: rust 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Jan 14, 2025
@niklaskorz niklaskorz force-pushed the remove-build-rust-crate branch from b1eb9c0 to 21a17f4 Compare January 14, 2025 14:52
@github-actions github-actions bot added the 8.has: documentation This PR adds or changes documentation label Jan 14, 2025
@niklaskorz niklaskorz force-pushed the remove-build-rust-crate branch from 21a17f4 to b876438 Compare January 14, 2025 14:56
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog labels Jan 14, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10 and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Jan 14, 2025
@niklaskorz niklaskorz force-pushed the remove-build-rust-crate branch from b876438 to 02bd0ea Compare January 14, 2025 15:02
@emilazy
Copy link
Member

emilazy commented Jan 14, 2025

We have other language‐specific packaging utilities in Nixpkgs that can’t be used in Nixpkgs (e.g., various modes that let you IFD a lock file). I’m not sure why this one specifically needs to be removed? But I don’t object to moving it to crate2nix, if nothing else is using it at this point.

@niklaskorz
Copy link
Contributor Author

We have other language‐specific packaging utilities in Nixpkgs that can’t be used in Nixpkgs (e.g., various modes that let you IFD a lock file). I’m not sure why this one specifically needs to be removed? But I don’t object to moving it to crate2nix, if nothing else is using it at this point.

At yesterday's Nix Darmstadt meetup, I raised the question of what the usual procedure for build helpers not anymore required by other packages in nixpkgs is, and was encouraged to open a PR for proposing the removal, one of the reasons being to reduce bloat of the nixpkgs repository.
If the final outcome is a rejection of this PR combined with renewed interest in maintaining both buildRustCrate and defaultCrateOverrides in-tree, I am perfectly happy with that as well.

@niklaskorz
Copy link
Contributor Author

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 373744


x86_64-linux

⏩ 2 packages blacklisted:
  • nixos-install-tools
  • tests.nixos-functions.nixos-test
✅ 1 package built:
  • nixpkgs-manual

aarch64-linux

⏩ 2 packages blacklisted:
  • nixos-install-tools
  • tests.nixos-functions.nixos-test
✅ 1 package built:
  • nixpkgs-manual

x86_64-darwin

✅ 1 package built:
  • nixpkgs-manual

aarch64-darwin

✅ 1 package built:
  • nixpkgs-manual

@niklaskorz niklaskorz marked this pull request as ready for review January 14, 2025 15:22
@@ -3679,21 +3679,6 @@
"rust-package-built-with-meson": [
"index.html#rust-package-built-with-meson"
],
"compiling-rust-crates-using-nix-instead-of-cargo": [
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't simply delete old locations, but redirect them to release notes. That way whoever has a bookmark will instantly find the reason why the thing they were using is gone.

@flokli
Copy link
Contributor

flokli commented Jan 14, 2025

At yesterday's Nix Darmstadt meetup, I raised the question of what the usual procedure for build helpers not anymore required by other packages in nixpkgs is, and was encouraged to open a PR for proposing the removal, one of the reasons being to reduce bloat of the nixpkgs repository.
If the final outcome is a rejection of this PR combined with renewed interest in maintaining both buildRustCrate and defaultCrateOverrides in-tree, I am perfectly happy with that as well.

crate2nix relies heavily on both buildRustCrate and defaultCrateOverrides. Kicking this out of nixpkgs would mean Cargo.nix files generated by it would either need to also contain that code, or pull this from yet another repository. It might also accidentally break cross-compilation functionality, as refactors in nixpkgs might require updates to there.

I'm personally not a fan of this change, at least not without fully understanding the implications. In this form, it'll simply break all crate2nix-packaged projects on the next nixpkgs bump if merged.

@niklaskorz
Copy link
Contributor Author

I'm personally not a fan of this change, at least not without fully understanding the implications. In this form, it'll simply break all crate2nix-packaged projects on the next nixpkgs bump if merged.

Thank you for the feedback, @flokli. Do you think an approach from the opposite direction, bringing buildRustCrate and defaultCrateOverrides into crate2nix before considering them for removal from nixpkgs, may be more acceptable? If so, I would be willing to work on such a PR and only bring back this one once we have found an acceptable solution.

Regarding the concern of having to bring in buildRustCrate into Cargo.nix from a source other than nixpkgs, this is already the norm for most "2nix" projects in the ecosystem, such as gomod2nix, cargo2nix or yarnpnp2nix.

@flokli
Copy link
Contributor

flokli commented Jan 16, 2025

I'm personally not a fan of this change, at least not without fully understanding the implications. In this form, it'll simply break all crate2nix-packaged projects on the next nixpkgs bump if merged.

Thank you for the feedback, @flokli. Do you think an approach from the opposite direction, bringing buildRustCrate and defaultCrateOverrides into crate2nix before considering them for removal from nixpkgs, may be more acceptable? If so, I would be willing to work on such a PR and only bring back this one once we have found an acceptable solution.

Regarding the concern of having to bring in buildRustCrate into Cargo.nix from a source other than nixpkgs, this is already the norm for most "2nix" projects in the ecosystem, such as gomod2nix, cargo2nix or yarnpnp2nix.

Moving it out of nixpkgs would mean crate2nix would need to start vendoring all this into every repo using it. I still think it makes more sense to keep this code in nixpkgs. At least defaultCrateOverrides can be useful for consumers other than crate2nix, and orchestrating things like cross-compilation fixes with nixpkgs while buildRustCrate doesn't live in there sounds like a lot of unnecessary toil.

Is it really so much of a liablilty to keep it in nixpkgs?

@Atemu
Copy link
Member

Atemu commented Jan 17, 2025

The original premise was that this smelled like dead code of a builder that nobody within Nixpkgs uses for anything.

If it's actively used in this way, I'd rather keep it in Nixpkgs too.

This fact should be clearly documented though and I think the same people who maintain crate2nix should maintain that code.

@niklaskorz
Copy link
Contributor Author

Alright, I will close this PR and refer to it if the topic comes up again. As keeping both buildRustCrate and defaultCrateOverrides in-tree appears to be the preference, I'll instead dedicate my time to improving the defaultCrateOverrides, starting with #374416.

@niklaskorz niklaskorz closed this Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: rust 8.has: changelog 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants