Skip to content

Impossible to override arguments of rustPlatform.fetchCargoVendor #415397

Open

Description

@axelkar

It's practically impossible to override the src and hash arguments of rustPlatform.fetchCargoVendor. You can copy code from Nixpkgs and try to reuse vendorStaging, but there's a clear issue here.

The switch from fetchCargoTarball to fetchCargoVendor broke the previous way of using overrideAttrsand setting src and outputHash.

I'm unsure how to amend this myself as the FOD in fetchCargoVendor is wrapped. Maybe something like lib.extendMkDerivation could be used here?


The issue with buildRustPackage not yet fully utilizing finalAttrs is adjacent but not directly in the scope of this issue, but I'll document it here regardless:

let
  pkgs = import <nixpkgs> {};
  myPkg = pkgs.rustPlatform.buildRustPackage {
    name = "example";
    src = pkgs.hello;
    cargoHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
  };
in
(myPkg.overrideAttrs { cargoHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABB="; }).cargoDeps
== myPkg.cargoDeps

# These should be inequal but they aren't

Related:

@9999years @amesgen @ShamrockLee

#194475 (comment) #107070 #382550

Activity

  1. added
    0.kind: bug
    0.kind: regression
    on Jun 9, 2025
  2. axelkar commented on Jun 9, 2025

    @axelkar
    MemberAuthor

    @TomaSajt mentionted for creating rustPlatform.fetchCargoVendor

  3. ShamrockLee commented on Jun 9, 2025

    @ShamrockLee
    Contributor

    Aside from making cargoHash and other vendor-related arguments overridable, we could also override cargoDeps.

  4. changed the title [-]Impossible to override rustPlatform.fetchCargoVendor[/-] [+]Impossible to override arguments of rustPlatform.fetchCargoVendor[/+] on Jun 9, 2025
  5. axelkar commented on Jun 9, 2025

    @axelkar
    MemberAuthor

    Aside from making cargoHash and other vendor-related arguments overridable, we could also override cargoDeps.

    Yes. That's what this issue focuses on, and that would make it at least possible to update the Cargo vendor hash.


    Overridability list

    Here's how I picture everything currently: (below layers can't affect above layers)

    1. Arguments to original package definition updated by override if defined using pkgs.callPackage
    2. Arguments to rustPlatform.buildRustPackage set in the original package definition.
    3. Arguments to stdenv.mkDerivation by rustPlatform.buildRustPackage. Includes the creation of cargoDeps from cargoHash etc.
    4. Arguments to stdenv.mkDerivation updated by overrideAttrs
    5. Arguments to builtins.derivation set by stdenv.mkDerivation logic
    6. Arguments to builtins.derivation updated by overrideDerivation
    7. builtins.derivation

    Integrating 2 and 4 can be done in the package definition easily by using finalAttrs, and the integration of layers 3 and 4 is what buildRustPackage needs to implement itself.

    Perhaps a visualization like the above could be paraphrased into the Nixpkgs manual? Oh and this all reminds me about infuse.nix :)

  6. added
    2.status: stale
    on Dec 7, 2025
  7. removed
    2.status: stale
    on Dec 15, 2025
  8. added
    2.status: stale
    on Dec 15, 2025
  9. added
    6.topic: rust
    on Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug0.kind: regression2.status: stale6.topic: rust

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions