crate2nix
crate2nix copied to clipboard
How to run clippy in a check
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.
This is a bit of a hack, but one way to do it is:
- Rather than calling
${generated}/default.nix
, copy your source tree somewhere writeable and${generated}/cargo/config
into.cargo/config.toml
in that directory. - If there isn't a Cargo.lock file in your source directory, copy that into place too (you'd need to be running #276 for this to be the case, I think)
- Add
${rustc}/bin
to your$PATH
. I also had to add${gcc}/bin
for one of my crates which hadcc
as a dev-dependency. - 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.
Oh, I found an even more straightforward way!
- cd into
${generated}/crate
- 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
.