2021-12-27 03:18:22 +03:00
|
|
|
{ cargo
|
2021-12-27 04:10:04 +03:00
|
|
|
, configureCargoCommonVarsHook
|
2021-12-27 03:18:22 +03:00
|
|
|
, configureCargoVendoredDepsHook
|
2021-12-27 05:06:19 +03:00
|
|
|
, copyCargoTargetToOutputHook
|
2021-12-29 02:15:10 +03:00
|
|
|
, inheritCargoTargetHook
|
2021-12-27 03:18:22 +03:00
|
|
|
, lib
|
|
|
|
, stdenv
|
2021-12-29 02:15:10 +03:00
|
|
|
, vendorCargoDeps
|
2021-12-27 03:18:22 +03:00
|
|
|
}:
|
|
|
|
|
2021-12-27 07:25:36 +03:00
|
|
|
{ doCompressTarget ? true
|
|
|
|
, doCopyTarget ? true
|
2021-12-27 05:06:19 +03:00
|
|
|
, nativeBuildInputs ? [ ]
|
|
|
|
, outputs ? [ "out" ]
|
|
|
|
, ...
|
|
|
|
}@args:
|
2021-12-29 02:15:10 +03:00
|
|
|
let
|
|
|
|
vendorFromCargoLockPath = path:
|
|
|
|
let
|
|
|
|
cargoLock = path + "/Cargo.lock";
|
|
|
|
in
|
|
|
|
if builtins.pathExists cargoLock
|
|
|
|
then vendorCargoDeps { inherit cargoLock; }
|
|
|
|
else
|
|
|
|
throw ''
|
|
|
|
unable to find Cargo.lock at ${path}. please ensure one of the following:
|
|
|
|
- a Cargo.lock exists at the root of the source directory of the derivation
|
|
|
|
- set `cargoVendorDir = vendorCargoDeps { cargoLock = ./some/path/to/Cargo.lock; }`
|
|
|
|
- set `cargoVendorDir = null` to skip vendoring altogether
|
|
|
|
'';
|
2021-12-27 05:06:19 +03:00
|
|
|
|
2021-12-29 02:15:10 +03:00
|
|
|
defaultValues = {
|
|
|
|
inherit
|
|
|
|
doCompressTarget
|
|
|
|
doCopyTarget;
|
2021-12-27 03:18:22 +03:00
|
|
|
|
2021-12-29 02:15:10 +03:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
cargo check --release
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
2021-12-27 05:06:19 +03:00
|
|
|
|
2021-12-29 02:15:10 +03:00
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
mkdir -p $out
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
2021-12-27 03:18:22 +03:00
|
|
|
|
2021-12-29 02:15:10 +03:00
|
|
|
cargoVendorDir =
|
|
|
|
if args ? src
|
|
|
|
then vendorFromCargoLockPath args.src
|
|
|
|
else null;
|
|
|
|
};
|
|
|
|
|
|
|
|
additions = {
|
|
|
|
outputs = outputs ++ lib.optional doCopyTarget "target";
|
|
|
|
|
|
|
|
nativeBuildInputs = nativeBuildInputs ++ [
|
|
|
|
cargo
|
|
|
|
configureCargoCommonVarsHook
|
|
|
|
configureCargoVendoredDepsHook
|
|
|
|
copyCargoTargetToOutputHook
|
|
|
|
inheritCargoTargetHook
|
|
|
|
];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation (defaultValues // args // additions)
|