Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run clippy in a check #195

Open
jeffa5 opened this issue May 16, 2021 · 2 comments
Open

How to run clippy in a check #195

jeffa5 opened this issue May 16, 2021 · 2 comments

Comments

@jeffa5
Copy link

jeffa5 commented May 16, 2021

Making a derivation that runs cargo clippy fails due to trying to download the dependencies.

Looking at the clippy page it seems it can be run as rustc using clippy-driver. Is there a way with the crate2nix logic to follow this through or does something need to be added to buildRustCrate in nixpkgs?

If there is another nice way to run clippy in a derivation (looking at it for a flake check) then that would also be great.

@apoelstra
Copy link
Contributor

This is a bit of a hack, but one way to do it is:

  1. Rather than calling ${generated}/default.nix, copy your source tree somewhere writeable and ${generated}/cargo/config into .cargo/config.toml in that directory.
  2. If there isn't a Cargo.lock file in your source directory, copy that into place too (you'd need to be running add ability to override lockfile from tools.nix #276 for this to be the case, I think)
  3. Add ${rustc}/bin to your $PATH. I also had to add ${gcc}/bin for one of my crates which had cc as a dev-dependency.
  4. Run cargo clippy --locked in the source directory.

The first and last steps are the real magic. The rest are just fixing things up. I think, in the absense of worktrees, you may also be able to do this in a Cargo.nix testPostRun block without needing to do any source code copying or other shenanigans.

@apoelstra
Copy link
Contributor

apoelstra commented Mar 5, 2023

Oh, I found an even more straightforward way!

  1. cd into ${generated}/crate
  2. Run CARGO_TARGET_DIR=<somewhere writeable> CARGO_HOME=../cargo/ cargo clippy --locked.

This avoids copying and ensures you're using the same lockfile that crate2nix used to produce the cargo config. You may still need to patch up your $PATH.

apoelstra added a commit to apoelstra/local-nix-ci that referenced this issue Mar 10, 2023
Also comment on crate2nix issue explaining how to do it: nix-community/crate2nix#195
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants