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";