crate2nix icon indicating copy to clipboard operation
crate2nix copied to clipboard

error: no matching package named `...` found

Open srid opened this issue 3 years ago • 12 comments

I get this really strange error but only in flakes. nix-build is fine, but nix run breaks. And it only happens if the git working copy is not dirty.

++ crate2nix generate -f ./Cargo.toml -o Cargo-generated.nix -h /nix/store/0v78qgpw835pb2ri7r1l1v40linxhi5a-himalaya-crate2nix/crate-hashes.json
Error: while retrieving metadata about ./Cargo.toml: Error during execution of `cargo metadata`: error: no matching package named `clap` found
location searched: registry `https://github.com/rust-lang/crates.io-index`
required by package `himalaya v0.2.2 (/build/source)`

crate2nix failed.

The source tree to reproduce this is here: https://github.com/srid/himalaya/commit/fce129d6a36f8b535ce042ddcd611b4a73120a88

By the way, I came across crate2nix via a conversation on reddit, which has further context on this problem.

srid avatar Apr 08 '21 03:04 srid

And I'm positive that this has nothing to do with the package in question, clap.

Confirmed here,

  • https://github.com/srid/bouncy/runs/2293288367
  • https://github.com/srid/bouncy/runs/2293424388

srid avatar Apr 08 '21 04:04 srid

I'm getting something similar with git2, which is definitely on [crates.io[(https://crates.io/crates/git2) :) Did you get anywhere with this @srid? I'm attempting to use your template, so big thank you :smile:

The output of nix log:

@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/g4jpfwmr91dw617ff82im9c9l3lrsnw1-gmr84gzz6syc4mr914i0j1mavbxy5k63-source
source root is gmr84gzz6syc4mr914i0j1mavbxy5k63-source
@nix { "action": "setPhase", "phase": "buildPhase" }
building
++ crate2nix generate -f ./Cargo.toml -o Cargo-generated.nix -h /nix/store/n56d3lm4wv548angjcafsw543ryvx1wy-my-app-crate2nix/crate-hashes.json
Error: while retrieving metadata about ./Cargo.toml: `cargo metadata` exited with an error: error: no matching package named `git2` found
location searched: registry `crates-io`
required by package `radicle-source v0.2.1 (/build/gmr84gzz6syc4mr914i0j1mavbxy5k63-source/source)`
crate2nix failed.

FintanH avatar Feb 28 '22 15:02 FintanH

@FintanH No, I no longer use Rust. Still using Haskell :-)

srid avatar Feb 28 '22 18:02 srid

@FintanH try using strace to get the underlying cargo metadata command? This might be an issue for upstream.

Ericson2314 avatar Mar 01 '22 03:03 Ericson2314

No, I no longer use Rust. Still using Haskell :-)

lol, very envious :)

try using strace to get the underlying cargo metadata command? This might be an issue for upstream.

@Ericson2314 thanks for the suggestion! I gave that a go, but it seems like crate2nix is using the cargo_metadata package :sweat: I couldn't see anything out of the ordinary happening.

Two things that are weird:

  1. If I drop into a shell nix-shell -p crate2nix and run crate2nix generate it works perfectly fine.
  2. If I commit Cargo.lock it works perfectly fine.

So it seems like a combination of not having a Cargo.lock with this flake setup is messing things up. I'd rather not have a Cargo.lock in the repository because it's a library package.

FintanH avatar Mar 01 '22 12:03 FintanH

I did some digging by pointing to my own crate2nix fork and building off of a custom revision. I printed the command that gets executed:

cargo metadata --format-version 1 --manifest-path ./Cargo.toml --all-features --locked

The weird thing is that this works if I run it from my terminal! :grimacing: I can only reproduce this error via nix build :(

FintanH avatar Mar 01 '22 14:03 FintanH

Try running that command without network access? I bet it's trying to download stuff to make a lock file on the fly.

Ericson2314 avatar Mar 01 '22 21:03 Ericson2314

Try running that command without network access? I bet it's trying to download stuff to make a lock file on the fly.

Hmmmm you're right! Why is that an issue?

FintanH avatar Mar 02 '22 10:03 FintanH

You do fundamentally need a lockfile to use crate2nix. Without one there is not concrete buildplans, just some constraints. crate2nix doesn't want to duplicate Cargo in learning how to satisfy those constraints, it wants just just tranform concrete build plans into Nix.

You mention this is a library, are you trying to CI the library?

Ericson2314 avatar Mar 02 '22 17:03 Ericson2314

You do fundamentally need a lockfile to use crate2nix. Without one there is not concrete buildplans, just some constraints. crate2nix doesn't want to duplicate Cargo in learning how to satisfy those constraints, it wants just just tranform concrete build plans into Nix.

Ya, I suppose that makes sense :)

You mention this is a library, are you trying to CI the library?

I am indeed, but also wanted to have nix flake to be able to CI the library but also have the same file define what the dev shell would look. I think what I'm going to go for is just use niv to pin dependencies and build with a default.nix file -- via nix-shell default.nix --run cmd -- and develop with shell.nix.

FintanH avatar Mar 02 '22 17:03 FintanH

We do have a set of binaries that seem open nix flaking since we have a Cargo.lock there, but unfortunately I ran into this number https://github.com/NixOS/nix/pull/4638 :upside_down_face:

FintanH avatar Mar 02 '22 17:03 FintanH

Yes the fact of the matter is you want to keep 1 or more Cargo.locks that don't go to crates.io when the library is published, but are used for CI. I general. packaged have "extract stuff" that isn't published for downstream consumption, but useful for development.

I dislike flakes, but anyways flake problems are anyways out of scope here. https://github.com/NixOS/nix/pull/4638 you can avoid but just writing down the reference? But niv and nix-thunk shouldn't suffer from it.

Ericson2314 avatar Mar 02 '22 19:03 Ericson2314