Skip to content

rustPlatform.fetchCargoVendor: allow duplicated dependencies #387337

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

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from

Conversation

TomaSajt
Copy link
Contributor

@TomaSajt TomaSajt commented Mar 5, 2025

Since this is a breaking change (even if mostly internal), let's not merge before we decide on a final design.
Reviews are welcome.

Fixes #359340
Fixes #30742

Related:


This PR contains the simpler but arguably more important part of #282798.
The other PR tries to migrate both importCargoLock and fetchCargoVendor, but this one only does the fetchCargoVendor change.

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 General-purpose programming language emphasizing performance, type safety, and concurrency. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin 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-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. labels Mar 5, 2025
@TomaSajt TomaSajt force-pushed the fetch-cargo-vendor-dup branch from f7be6ba to 27dd560 Compare March 5, 2025 17:20
@nyabinary
Copy link
Contributor

Should target staging considering the amount of rebuilds

@TomaSajt
Copy link
Contributor Author

TomaSajt commented Mar 5, 2025

Yes I'll point it there soon, but I still have a few TODOs.

@TomaSajt TomaSajt force-pushed the fetch-cargo-vendor-dup branch from 7a1c9bb to b0e4125 Compare March 5, 2025 18:18
@TomaSajt TomaSajt changed the base branch from master to staging March 5, 2025 18:18
@TomaSajt TomaSajt marked this pull request as ready for review March 5, 2025 18:23
@nix-owners nix-owners bot requested review from mmahut and RaghavSood March 5, 2025 18:24
@TomaSajt TomaSajt force-pushed the fetch-cargo-vendor-dup branch from b0e4125 to 1cf6ec4 Compare March 5, 2025 18:28
@github-actions github-actions bot added the 6.topic: python Python is a high-level, general-purpose programming language. label Mar 5, 2025
@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Mar 5, 2025
@TomaSajt TomaSajt force-pushed the fetch-cargo-vendor-dup branch from 1cf6ec4 to 242f358 Compare March 5, 2025 19:49
@github-actions github-actions bot removed the 6.topic: python Python is a high-level, general-purpose programming language. label Mar 5, 2025
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Mar 5, 2025
@TomaSajt TomaSajt force-pushed the fetch-cargo-vendor-dup branch from 242f358 to 6899498 Compare March 8, 2025 13:44
@poelzi
Copy link
Member

poelzi commented Mar 16, 2025

Unfortunately, this does not fix the sui problem. I debugged it by adding "set -x" on the cargo-vendor-dir command:

+++ ln -s /nix/store/a3hq2s4jsrjlk5flzm6bwibc63habljn-tokio-io-timeout-1.2.0 /nix/store/hrw1qsrqh3mfasw72hlapd0lnkd303a1-cargo-vendor-dir/tokio-io-timeout-1.2.0
+++ '[' -e /nix/store/a3hq2s4jsrjlk5flzm6bwibc63habljn-tokio-io-timeout-1.2.0/.cargo-config ']'
+++ for crate in /nix/store/w4njzhl6c2ap84kd6v9c09g3vb3jwpwr-Inflector-0.11.4 /nix/store/61myz4b2wg5bcwrmcgqir98p1kjh0yjf-addchain-0.2.0 /nix/store/dfdynm0vivlyw1cyxabpnkmk0gbfvn6v-add>
++++ basename /nix/store/pbkdlfdqi3gzigz428kbay8fcwvv6z7z-tokio-macros-2.5.0
++++ cut -c 34-
+++ ln -s /nix/store/pbkdlfdqi3gzigz428kbay8fcwvv6z7z-tokio-macros-2.5.0 /nix/store/hrw1qsrqh3mfasw72hlapd0lnkd303a1-cargo-vendor-dir/tokio-macros-2.5.0
+++ '[' -e /nix/store/pbkdlfdqi3gzigz428kbay8fcwvv6z7z-tokio-macros-2.5.0/.cargo-config ']'
+++ for crate in /nix/store/w4njzhl6c2ap84kd6v9c09g3vb3jwpwr-Inflector-0.11.4 /nix/store/61myz4b2wg5bcwrmcgqir98p1kjh0yjf-addchain-0.2.0 /nix/store/dfdynm0vivlyw1cyxabpnkmk0gbfvn6v-add>
++++ basename /nix/store/rk97wgy1a6m8x9z5k05dzw1fmhbqb3wx-tokio-macros-2.5.0
++++ cut -c 34-
+++ ln -s /nix/store/rk97wgy1a6m8x9z5k05dzw1fmhbqb3wx-tokio-macros-2.5.0 /nix/store/hrw1qsrqh3mfasw72hlapd0lnkd303a1-cargo-vendor-dir/tokio-macros-2.5.0
ln: failed to create symbolic link '/nix/store/hrw1qsrqh3mfasw72hlapd0lnkd303a1-cargo-vendor-dir/tokio-macros-2.5.0/rk97wgy1a6m8x9z5k05dzw1fmhbqb3wx-tokio-macros-2.5.0': Permission den>
+ exitHandler
+ exitCode=1
+ set +e
+ '[' -n '' ']'
+ ((  1 != 0  ))
+ runHook failureHook
+ local hookName=failureHook

The problem is triggered by 2 versions of the tokio-macros used by sui

@TomaSajt
Copy link
Contributor Author

TomaSajt commented Mar 16, 2025

You are using cargoLock.lockFile (backend: importCargoLock)
instead of cargoHash + useFetchCargoVendor = true (backend: fetchCargoVendor).

In this PR I only modified fetchCargoVendor.

I was able to build sui with this:
(do note that you need like over 100GiB of storage to build it...)

{
  lib,
  rustPlatform,
  fetchFromGitHub,
  pkg-config,
  zstd,
}:

rustPlatform.buildRustPackage (finalAttrs: {
  pname = "sui";
  version = "1.43.1";

  src = fetchFromGitHub {
    owner = "MystenLabs";
    repo = "sui";
    tag = "mainnet-v${finalAttrs.version}";
    hash = "sha256-mNljh3HupusGmfT3pXtjqUp7OZHhyWd6jNiFiKlSYpk=";
  };

  useFetchCargoVendor = true;
  cargoHash = "sha256-ckotvpQw3WfvJ2YXR/XKT7LamGj7kLtGwMR/qrXpmYc=";

  nativeBuildInputs = [
    pkg-config
    rustPlatform.bindgenHook
  ];

  buildInputs = [
    zstd
  ];

  env = {
    # if this is not set the build will try to invoke git to get the rev
    GIT_REVISION = "nixpkgs@${finalAttrs.version}";
    ZSTD_SYS_USE_PKG_CONFIG = true;
  };

  # the build takes up more than 60G of space even without the checks
  # my system ran out of space (150G) when having tests enabled
  doCheck = false;

})

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Mar 16, 2025
@poelzi
Copy link
Member

poelzi commented Mar 17, 2025

Ahh, I see. I used useFetchCargoVendor = true and cargoLock.
Works now, thanks a lot 👍🏽

@TomaSajt TomaSajt force-pushed the fetch-cargo-vendor-dup branch from 6899498 to bb8c648 Compare March 23, 2025 20:14
@github-actions github-actions bot added 6.topic: python Python is a high-level, general-purpose programming language. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Mar 23, 2025
@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jun 19, 2025
@TomaSajt TomaSajt force-pushed the fetch-cargo-vendor-dup branch from 209af14 to 76ef3a6 Compare June 19, 2025 08:50
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jun 19, 2025
@TomaSajt TomaSajt force-pushed the fetch-cargo-vendor-dup branch 3 times, most recently from a9451c9 to d5bf49d Compare June 23, 2025 11:10
@TomaSajt TomaSajt marked this pull request as draft June 23, 2025 11:11
@TomaSajt TomaSajt force-pushed the fetch-cargo-vendor-dup branch from d5bf49d to 27a4b31 Compare June 23, 2025 11:12
@TomaSajt TomaSajt marked this pull request as ready for review June 23, 2025 11:12
@TomaSajt TomaSajt force-pushed the fetch-cargo-vendor-dup branch from 27a4b31 to cce9f4e Compare July 3, 2025 22:29
Copy link
Member

@DavHau DavHau left a comment

Choose a reason for hiding this comment

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

I tested this patch today on a project where it was running into the failed to create symbolic link error and it fixed it successfully.

EDIT: Though I'm now running into an error like this:

 error: failed to select a version for the requirement `cfg-if = "^1.0"` (locked to 1.0.0)

Not sure if this is related to the fetching or not

EDIT: forget about it. This seems to be an unrelated issue

@TomaSajt
Copy link
Contributor Author

TomaSajt commented Jul 4, 2025

I tested this patch today on a project where it was running into the failed to create symbolic link error and it fixed it successfully.

EDIT: Though I'm now running into an error like this:

 error: failed to select a version for the requirement `cfg-if = "^1.0"` (locked to 1.0.0)

Not sure if this is related to the fetching or not

If this is a public project, please share a link to it.
If not, please share some more details/logs.

@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 8, 2025
@DavHau
Copy link
Member

DavHau commented Aug 3, 2025

@TomaSajt My issue seems to be unrelated. Please don't feel blocked by it

@TomaSajt TomaSajt force-pushed the fetch-cargo-vendor-dup branch from cce9f4e to 7c0a412 Compare August 14, 2025 14:41
@nixpkgs-ci nixpkgs-ci bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 14, 2025
@MultisampledNight
Copy link
Member

Packaging Kiesel seems to be blocked on this.

Kiesel uses an in-tree Rust crate for some FFI, which depends partly on crates.io versions, partly on git versions to get the latest fixes. A lot of transitive deps are duplicated in turn, too.
Just replacing them with crates.io is not practical, as the rest of the project also has the exact git commits pinned.
(Current attempt is at MultisampledNight@ec0f801 if anybody is curious, very half-baked.)

This was referenced Aug 20, 2025
Copy link
Member

@MultisampledNight MultisampledNight left a comment

Choose a reason for hiding this comment

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

Simple enough impl, impact is bearable.

Comment on lines 274 to 282
next_registry_ind = 1
next_git_ind = 0

source_config = {}

source_config["_vendored-source-registry-0"] = {}
source_config["_vendored-source-registry-0"]["directory"] = "@vendor@/source-registry-0"
source_config["crates-io"] = {}
source_config["crates-io"]["replace-with"] = "_vendored-source-registry-0"
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Could maybe refactor this to instead store lists of registry and git sources, then constructing the source_config afterwards. This would avoid bugs due to missing to increment the indices. Works fine as-is though.

@nixpkgs-ci nixpkgs-ci bot added 2.status: merge conflict This PR has merge conflicts with the target branch 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Aug 21, 2025
@TomaSajt TomaSajt force-pushed the fetch-cargo-vendor-dup branch from 7c0a412 to e4d6c16 Compare August 23, 2025 23:23
This is achieved by having subdirs in the vendor dir
This is needed because the previous commit moved crates one
layer deeper in the vendor directory of rust packages when using
fetchCargoVendor
@TomaSajt TomaSajt force-pushed the fetch-cargo-vendor-dup branch from e4d6c16 to 4094669 Compare August 23, 2025 23:26
@nixpkgs-ci nixpkgs-ci bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 23, 2025
@TomaSajt
Copy link
Contributor Author

Pushed a change factoring out some stuff to slightly de-clutter the create_vendor function and hopefully made some of the logic more readable.
Diff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: rust General-purpose programming language emphasizing performance, type safety, and concurrency. 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. 12.approvals: 2 This PR was reviewed and approved by two persons. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages.
Projects
None yet
Development

Successfully merging this pull request may close these issues.