diff --git a/pkgs/build-support/rust/build-rust-package/default.nix b/pkgs/build-support/rust/build-rust-package/default.nix index 679e10a3442e..a7a9d9b52fc0 100644 --- a/pkgs/build-support/rust/build-rust-package/default.nix +++ b/pkgs/build-support/rust/build-rust-package/default.nix @@ -11,6 +11,7 @@ , cargoInstallHook , cargoNextestHook , cargoSetupHook +, cargo-auditable , rustc , libiconv , windows @@ -42,6 +43,7 @@ , buildFeatures ? [ ] , checkFeatures ? buildFeatures , useNextest ? false +, auditable ? true , depsExtraArgs ? {} # Toggles whether a custom sysroot is created when the target is a .json file. @@ -113,6 +115,8 @@ stdenv.mkDerivation ((removeAttrs args [ "depsExtraArgs" "cargoUpdateHook" "carg cargoCheckFeatures = checkFeatures; + cargoCommand = if auditable then "cargo auditable" else "cargo"; + patchRegistryDeps = ./patch-registry-deps; nativeBuildInputs = nativeBuildInputs ++ [ @@ -123,6 +127,8 @@ stdenv.mkDerivation ((removeAttrs args [ "depsExtraArgs" "cargoUpdateHook" "carg cargoInstallHook cargoSetupHook rustc + ] ++ lib.optionals auditable [ + cargo-auditable ]; buildInputs = buildInputs diff --git a/pkgs/build-support/rust/hooks/cargo-build-hook.sh b/pkgs/build-support/rust/hooks/cargo-build-hook.sh index 7503fae4cd7f..0fe07d6e856e 100644 --- a/pkgs/build-support/rust/hooks/cargo-build-hook.sh +++ b/pkgs/build-support/rust/hooks/cargo-build-hook.sh @@ -31,7 +31,7 @@ cargoBuildHook() { "CXX_@rustBuildPlatform@=@cxxForBuild@" \ "CC_@rustTargetPlatform@=@ccForHost@" \ "CXX_@rustTargetPlatform@=@cxxForHost@" \ - cargo build -j $NIX_BUILD_CORES \ + ${cargoCommand-cargo} build -j $NIX_BUILD_CORES \ --target @rustTargetPlatformSpec@ \ --frozen \ ${cargoBuildProfileFlag} \ diff --git a/pkgs/build-support/rust/hooks/cargo-check-hook.sh b/pkgs/build-support/rust/hooks/cargo-check-hook.sh index 57fc2779cfe9..c2a909c76f6f 100644 --- a/pkgs/build-support/rust/hooks/cargo-check-hook.sh +++ b/pkgs/build-support/rust/hooks/cargo-check-hook.sh @@ -33,7 +33,7 @@ cargoCheckHook() { ( set -x - cargo test \ + ${cargoCommand-cargo} test \ -j $NIX_BUILD_CORES \ ${argstr} -- \ --test-threads=${threads} \ diff --git a/pkgs/build-support/rust/hooks/cargo-nextest-hook.sh b/pkgs/build-support/rust/hooks/cargo-nextest-hook.sh index de85683ead2a..a4ab778c298a 100644 --- a/pkgs/build-support/rust/hooks/cargo-nextest-hook.sh +++ b/pkgs/build-support/rust/hooks/cargo-nextest-hook.sh @@ -33,7 +33,7 @@ cargoNextestHook() { ( set -x - cargo nextest run \ + ${cargoCommand-cargo} nextest run \ -j ${threads} \ ${argstr} -- \ ${checkFlags} \ diff --git a/pkgs/development/compilers/rust/cargo.nix b/pkgs/development/compilers/rust/cargo.nix index 2c9a3b1af472..ec80533cc069 100644 --- a/pkgs/development/compilers/rust/cargo.nix +++ b/pkgs/development/compilers/rust/cargo.nix @@ -2,6 +2,7 @@ , file, curl, pkg-config, python3, openssl, cmake, zlib , installShellFiles, makeWrapper, cacert, rustPlatform, rustc , libiconv, CoreFoundation, Security +, auditable ? true }: rustPlatform.buildRustPackage { @@ -12,6 +13,8 @@ rustPlatform.buildRustPackage { cargoVendorDir = "vendor"; buildAndTestSubdir = "src/tools/cargo"; + inherit auditable; + passthru = { rustc = rustc; inherit (rustc) tests; diff --git a/pkgs/development/tools/rust/cargo-auditable/default.nix b/pkgs/development/tools/rust/cargo-auditable/default.nix index 64580d8ad8b3..52d647b2b0a5 100644 --- a/pkgs/development/tools/rust/cargo-auditable/default.nix +++ b/pkgs/development/tools/rust/cargo-auditable/default.nix @@ -1,23 +1,38 @@ -{ lib, rustPlatform, fetchFromGitHub }: +{ lib, fetchFromGitHub, makeRustPlatform, rustc, cargo }: -rustPlatform.buildRustPackage rec { - pname = "cargo-auditable"; - version = "0.5.5"; +let + args = rec { + pname = "cargo-auditable"; + version = "0.5.5"; - src = fetchFromGitHub { - owner = "rust-secure-code"; - repo = pname; - rev = "v${version}"; - sha256 = "sha256-mEmTgd7sC2jmYeb5pEO985v/aWWKlq/mSQUAGi32loY="; + src = fetchFromGitHub { + owner = "rust-secure-code"; + repo = pname; + rev = "v${version}"; + sha256 = "sha256-mEmTgd7sC2jmYeb5pEO985v/aWWKlq/mSQUAGi32loY="; + }; + + cargoSha256 = "sha256-G72UUqvFaTY/GQSkpz1wIzjb7vIWuAjvKMZosUB6YsA="; + + meta = with lib; { + description = "A tool to make production Rust binaries auditable"; + homepage = "https://github.com/rust-secure-code/cargo-auditable"; + changelog = "https://github.com/rust-secure-code/cargo-auditable/blob/v${version}/cargo-auditable/CHANGELOG.md"; + license = with licenses; [ mit /* or */ asl20 ]; + maintainers = with maintainers; [ figsoda ]; + }; }; - cargoSha256 = "sha256-G72UUqvFaTY/GQSkpz1wIzjb7vIWuAjvKMZosUB6YsA="; - - meta = with lib; { - description = "A tool to make production Rust binaries auditable"; - homepage = "https://github.com/rust-secure-code/cargo-auditable"; - changelog = "https://github.com/rust-secure-code/cargo-auditable/blob/v${version}/cargo-auditable/CHANGELOG.md"; - license = with licenses; [ mit /* or */ asl20 ]; - maintainers = with maintainers; [ figsoda ]; + rustPlatform = makeRustPlatform { + inherit rustc; + cargo = cargo.override { + auditable = false; + }; }; -} + + bootstrap = rustPlatform.buildRustPackage (args // { + auditable = false; + }); +in + +rustPlatform.buildRustPackage.override { cargo-auditable = bootstrap; } args