Skip to content

rustPlatform.importCargoLock fails with git dependencies of the same package and version #183344

Open

Description

@sbruder

Describe the bug

rustPlatform.importCargoLock, which is used by rustPlatform.buildRustPackage when cargoLock.lockFile is set, requires explicit hashes for all git dependencies in outputHashes.<package>, because their integrity can’t be verified otherwise. They are keyed by the package name and the version, which works fine for published crates, but can fail for git dependencies, where it is possible to have two packages with the same version but a different source URL (and therefore different contents and hashes).

Steps To Reproduce

Try to import the cargo lock file for any rust project that depends on different git revisions of one package that share the same (Cargo.toml metadata) version.

I found this when trying to build the firmware for Nitrokey 3 with Nix, but I also created a minimal example to isolate this: https://github.com/sbruder/nix-cargo-two-unpinned-dependencies

In case of the latter, the build fails with the following message, even though there is a hash specified for libc-0.2.126:

error: No hash was found while vendoring the git dependency libc-0.2.126. You can add
       a hash through the `outputHashes` argument of `importCargoLock`:

       outputHashes = {
         "libc-0.2.126" = "<hash>";
       };

       If you use `buildRustPackage`, you can add this attribute to the `cargoLock`
       attribute set.

Expected behavior

One should be able to specify the output hash for each git version of the package that is used separately.

Notify maintainers

@danieldk

Metadata

  • system: "x86_64-linux"
  • host os: Linux 5.18.12, NixOS, 22.05 (Quokka), 22.05.20220722.e3583ad
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.8.1
  • channels(root): ""
  • nixpkgs: /nix/store/v039w5dpnfqy2qvqq04a489s8zqvr4di-source

Activity

  1. added
    0.kind: bug
    on Jul 28, 2022
  2. added
    6.topic: rust
    on Aug 1, 2022
  3. magnetophon commented on Aug 3, 2022

    @magnetophon
    Member

    I just ran into the same issue.

  4. liferooter commented on Apr 14, 2024

    @liferooter
    Contributor

    Still actual issue though, just got it with Zed editor.

  5. risicle commented on Apr 14, 2024

    @risicle
    Contributor

    Same here, with qdrant.

  6. keks commented on Mar 31, 2025

    @keks
    Contributor

    I get the same error even though my Cargo.lock contains the offending package (a git dep) only once. Is that the same issue or should I file a new one?

  7. added
    2.status: stale
    on Sep 28, 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: bug2.status: stale6.topic: rust

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions