Does cargo tooling pick up wrong crate name or is it just me?

I’m trying to build alacritty with wayland clipboard support.

That’s the overlay that I wrote:

self: super:

{
  alacritty = super.rustPlatform.buildRustPackage (super.alacritty.drvAttrs // rec {
    name = "alacritty-${version}";
    version = "0.3.2b";

    src = super.fetchFromGitHub {
      owner = "chrisduerr";
      repo = "alacritty";
      rev = "1cae9f3538bb3442d314ea74f7c7d08917e9c08b";  # clipboard-rework
      sha256 = "111q0406z0q5dbrrhgw1knib0clz1rshimsj5css5x2wrjrdcw71";
    };
    cargoSha256 = "0000000000000000000000000000000000000000000000000000";
    postPatch = "";
  });
}

Output:

these derivations will be built:
  /nix/store/jdsrbagjbw3y7368g621gykcwkj6zpln-alacritty-0.3.2b-vendor.drv
  /nix/store/dzddnlkd1kfa5cmk864li9d7aydfknk1-alacritty-0.3.2b.drv
building '/nix/store/jdsrbagjbw3y7368g621gykcwkj6zpln-alacritty-0.3.2b-vendor.drv'...
unpacking sources
unpacking source archive /nix/store/zni202fyh29dkipvlr48lcx3f0v4lk5h-source
source root is source
patching sources
installing
    Updating registry `https://github.com/rust-lang/crates.io-index`
    Updating git repository `https://github.com/chrisduerr/rust-clipboard`
    Updating registry `https://github.com/rust-lang/crates.io-index`
    Updating registry `https://github.com/rust-lang/crates.io-index`
error: failed to sync

Caused by:
  failed to load pkg lockfile

Caused by:
  no matching package named `sctk` found (required by `smithay-clipboard`)
location searched: registry https://github.com/rust-lang/crates.io-index
version required: ^0.5
Traceback (most recent call last):
  File "/nix/store/fqb8mndpjmhckylsgznwb261q6v6iqkq-cargo-vendor-normalise/bin/.cargo-vendor-normalise-wrapped", line 42, in <module>
    main()
  File "/nix/store/fqb8mndpjmhckylsgznwb261q6v6iqkq-cargo-vendor-normalise/bin/.cargo-vendor-normalise-wrapped", line 17, in main
    assert list(data.keys()) == ["source"]
AssertionError
builder for '/nix/store/jdsrbagjbw3y7368g621gykcwkj6zpln-alacritty-0.3.2b-vendor.drv' failed with exit code 1
cannot build derivation '/nix/store/dzddnlkd1kfa5cmk864li9d7aydfknk1-alacritty-0.3.2b.drv': 1 dependencies couldn't be built
error: build of '/nix/store/dzddnlkd1kfa5cmk864li9d7aydfknk1-alacritty-0.3.2b.drv' failed

The newly introduced dependency smithay-clipboard does require sctk, but the proper name of the crate in the index is smithay-client-toolkit.

Did I do something wrong or is there an issue with cargo tooling in Nix that mixed up the names?

This is a problem with the cargo-vendor-0.1.13 version in the currently published channel. It boils down to the following from smithay-clipboard’s Cargo.toml:

sctk = { package = "smithay-client-toolkit", version = "0.5" }

Specifically, it’s using a dependency name that doesn’t match the actual package name. The old cargo-vendor doesn’t understand the package key and so tries to find it with the wrong name.

The current nixpkgs master has an updated version cargo-vendor-0.1.23 that fixes this problem.

Edit: I just updated my channel and nixpkgs-unstable now has cargo-vendor-0.1.23. This must have been published sometime in the past day. Not sure about any other channels.

Edit 2: nixos-unstable-small also has cargo-vendor-0.1.23. Unfortunately nixos-19.03-small is still on cargo-vendor-0.1.13 despite being updated 3 hours ago, so it’s possible that nixos-19.03 isn’t expected to get the cargo-vendor update. If true, that’s unfortunate, given this issue.

1 Like

Wow, thanks for the writeup, that’s exactly what I needed to get unstuck!

I love how I simple it was to switch to the new tooling by adding a single unstable:

super.unstable.rustPlatform.buildRustPackage

where unstable came from

nixpkgs.overlays = [ (self: super: { unstable = import <nixos-unstable> { config = config.nixpkgs.config; };}) ];

For the future lurkers: this is what I needed to override the buildRustPackage arguments:

self: super:

{
  alacritty = super.unstable.rustPlatform.buildRustPackage rec {
    inherit (super.alacritty) buildInputs;

    name = "alacritty-${version}";
    version = "0.3.2b";

    src = super.fetchFromGitHub {
      owner = "chrisduerr";
      repo = "alacritty";
      rev = "1cae9f3538bb3442d314ea74f7c7d08917e9c08b";  # clipboard-rework
      sha256 = "111q0406z0q5dbrrhgw1knib0clz1rshimsj5css5x2wrjrdcw71";
    };
    cargoSha256 = "05wh91s9p06lff3jlrn100al04sxzrwakdx91c4magdqalr4yaij";
    postPatch = "";

    nativeBuildInputs = super.alacritty.nativeBuildInputs ++ [ super.python3 ];
  };

By the time you discover this, you probably won’t need the unstable bit.

Unfortunately, it seems to produce different Cargo SHA-256 hashes, at least for some derrivations :frowning::

https://github.com/NixOS/nixpkgs/issues/60668#issuecomment-493736428