From c2d7d083d5ee819dd3113dd5bcface1ffe4aa4c6 Mon Sep 17 00:00:00 2001 From: Ivan Petkov Date: Sun, 26 Dec 2021 17:10:04 -0800 Subject: [PATCH] Add configureCargoCommonVarsHook --- lib/buildWithCargo.nix | 2 ++ pkgs/configureCargoCommonVarsHook.sh | 15 +++++++++++++++ pkgs/default.nix | 5 +++++ 3 files changed, 22 insertions(+) create mode 100644 pkgs/configureCargoCommonVarsHook.sh diff --git a/lib/buildWithCargo.nix b/lib/buildWithCargo.nix index 72177bf..25b102c 100644 --- a/lib/buildWithCargo.nix +++ b/lib/buildWithCargo.nix @@ -1,4 +1,5 @@ { cargo +, configureCargoCommonVarsHook , configureCargoVendoredDepsHook , lib , stdenv @@ -8,6 +9,7 @@ args@{ nativeBuildInputs ? [ ], ... }: stdenv.mkDerivation (args // { nativeBuildInputs = nativeBuildInputs ++ [ cargo + configureCargoCommonVarsHook configureCargoVendoredDepsHook ]; diff --git a/pkgs/configureCargoCommonVarsHook.sh b/pkgs/configureCargoCommonVarsHook.sh new file mode 100644 index 0000000..c62bdda --- /dev/null +++ b/pkgs/configureCargoCommonVarsHook.sh @@ -0,0 +1,15 @@ +configureCargoCommonVars() { + echo "Executing configureCargoCommonVars" + + export CARGO_BUILD_JOBS=${CARGO_BUILD_JOBS:-$NIX_BUILD_CORES} + export RUST_TEST_THREADS=${RUST_TEST_THREADS:-$NIX_BUILD_CORES} + + # Disable incremental builds by default since we don't get a ton of benefit + # while building with nix. Allow a declared-but-empty variable which will tell + # cargo to honor the definition used in the build profile + export CARGO_BUILD_INCREMENTAL=${CARGO_BUILD_INCREMENTAL-false} + + echo "Finished configureCargoCommonVars" +} + +preConfigureHooks+=(configureCargoCommonVars) diff --git a/pkgs/default.nix b/pkgs/default.nix index d0a1e59..d749198 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,6 +1,11 @@ { makeSetupHook }: { + configureCargoCommonVarsHook = makeSetupHook + { + name = "configureCargoCommonVarsHook"; + } ./configureCargoCommonVarsHook.sh; + configureCargoVendoredDepsHook = makeSetupHook { name = "configureCargoVendoredDepsHook";