From b969657bf9609e5ee5a90b1181e542359f998fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Mon, 26 Feb 2024 14:35:36 +0100 Subject: [PATCH] rustfmt: wrap cargo-fmt with cargo Before it failed with this error: failed to start `cargo metadata`: No such file or directory (os error 2) Suffixing it to PATH to make sure any other cargo is used before this. --- pkgs/development/compilers/rust/rustfmt.nix | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/rust/rustfmt.nix b/pkgs/development/compilers/rust/rustfmt.nix index 9cc8df5a9e90..2a5f722a5b93 100644 --- a/pkgs/development/compilers/rust/rustfmt.nix +++ b/pkgs/development/compilers/rust/rustfmt.nix @@ -1,6 +1,14 @@ -{ lib, stdenv, rustPlatform, rustc, Security, asNightly ? false }: +{ lib +, stdenv +, cargo +, makeWrapper +, rustPlatform +, rustc +, Security +, asNightly ? false +}: -rustPlatform.buildRustPackage rec { +rustPlatform.buildRustPackage { pname = "rustfmt" + lib.optionalString asNightly "-nightly"; inherit (rustc) version src; @@ -11,6 +19,10 @@ rustPlatform.buildRustPackage rec { # changes hash of vendor directory otherwise dontUpdateAutotoolsGnuConfigScripts = true; + nativeBuildInputs = [ + makeWrapper + ]; + buildInputs = [ rustc.llvm ] ++ lib.optional stdenv.isDarwin Security; @@ -34,6 +46,11 @@ rustPlatform.buildRustPackage rec { CFG_RELEASE = rustc.version; CFG_RELEASE_CHANNEL = if asNightly then "nightly" else "stable"; + postInstall = '' + wrapProgram $out/bin/cargo-fmt \ + --suffix PATH : ${lib.makeBinPath [ cargo ]} + ''; + meta = with lib; { description = "A tool for formatting Rust code according to style guidelines"; homepage = "https://github.com/rust-lang-nursery/rustfmt";