yusdacra / nix-cargo-integration

Library to easily and effortlessly integrate Cargo projects with Nix.
https://flake.parts/options/nix-cargo-integration.html
MIT License
182 stars 19 forks source link

Cilppy 'invalid metadata' errors #138

Closed szg251 closed 11 months ago

szg251 commented 11 months ago

I installed clippy in my project, but I'm having an issue that I could not solve. This is how I added clippy:

      devShells."dev-${crateName}-rust" = config.nci.outputs.${crateName}.devShell.overrideAttrs (old: {
        packages = (old.packages or [ ]) ++ [ pkgs.rust-analyzer pkgs.clippy ];
      });

And this is the error I get:

error[E0786]: found invalid metadata files for crate `serde`
   --> src/json.rs:100:30
    |
100 |                     _ => Err(serde::ser::Error::custom(format!(
    |                              ^^^^^
    |
    = note: invalid metadata version found: /my/lovely/project/target/debug/deps/libserde-b13d990448a515c7.rmeta

For more information about this error, try `rustc --explain E0786`.

I'm still investigating the issue, but it seems like I'm using the wrong rustc version for clipppy. I tried the cleaning the target directory and applying rust-overlay following "nci/rust-overlay", but no success. Do you have any ideas?

Also, I think it would be a great idea, to expose some configuration to add these tools easily.

yusdacra commented 11 months ago

Instead of using the nixpkgs version of these tools you should use the perSystem.nci.toolchainConfig option to add these tools. Like here:

{
    nci.toolchainConfig = {
        channel = "stable";
        components = ["rust-analyzer" "rust-src" "clippy" "rustfmt"];
    };
}

(note that if you use a rust-toolchain.toml file nci will automatically use that)

szg251 commented 11 months ago

Oh, nice that sloved my problem!

szg251 commented 11 months ago

I have a followup question: my main environment was fixed, but I'm also using pre-commit hooks. I can supply custom tools to these, is there way to get these from nci? I was trying to get it with config.nci.toolchains.shell, but I had no luck yet..

yusdacra commented 11 months ago

config.nci.toolchains.shell is a derivation with all the components, so you should be able to do something like "${config.nci.toolchains.shell}/bin/cargo (or other binaries).