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 03:29:31 +03:00
|
|
|
, inheritCargoArtifactsHook
|
2021-12-29 04:51:51 +03:00
|
|
|
, installFromCargoArtifactsHook
|
2021-12-27 03:18:22 +03:00
|
|
|
, lib
|
2021-12-29 05:51:06 +03:00
|
|
|
, remapSourcePathPrefixHook
|
2021-12-27 03:18:22 +03:00
|
|
|
, stdenv
|
2021-12-29 02:15:10 +03:00
|
|
|
, vendorCargoDeps
|
2021-12-27 03:18:22 +03:00
|
|
|
}:
|
2021-12-29 02:27:49 +03:00
|
|
|
let
|
|
|
|
vendorCargoDepsFromArgs = args:
|
|
|
|
if args ? src
|
|
|
|
then
|
|
|
|
let
|
|
|
|
path = args.src;
|
|
|
|
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
|
|
|
|
''
|
|
|
|
else null;
|
|
|
|
in
|
2021-12-27 03:18:22 +03:00
|
|
|
|
2021-12-29 05:51:44 +03:00
|
|
|
{
|
|
|
|
# A directory to an existing cargo `target` directory, which will be reused
|
|
|
|
# at the start of the derivation. Useful for caching incremental cargo builds
|
|
|
|
cargoArtifacts ? null
|
|
|
|
# A directory of vendored cargo sources which can be consumed without network
|
|
|
|
# access. Directory structure should basically follow the output of `cargo vendor`
|
2021-12-29 03:29:31 +03:00
|
|
|
, cargoVendorDir ? vendorCargoDepsFromArgs args
|
2021-12-29 05:51:44 +03:00
|
|
|
# Controls whether cargo's `target` directory should be compressed when copied
|
|
|
|
# to the output at the end of the derivation.
|
2021-12-29 02:27:49 +03:00
|
|
|
, doCompressTarget ? true
|
2021-12-29 05:51:44 +03:00
|
|
|
# Controls whether cargo's `target` directory should be copied as an output
|
2021-12-29 02:19:10 +03:00
|
|
|
, doCopyTargetToOutput ? true
|
2021-12-29 05:51:44 +03:00
|
|
|
# Controls instructing rustc to remap the path prefix of any sources it
|
|
|
|
# captures (for example, this can include file names in panic info). This is
|
|
|
|
# useful to omit any references to `/nix/store/...` from the final binary,
|
|
|
|
# as including them will make Nix pull in all sources when installing any binaries.
|
2021-12-29 05:51:06 +03:00
|
|
|
, doRemapSourcePathPrefix ? true
|
2021-12-27 05:06:19 +03:00
|
|
|
, nativeBuildInputs ? [ ]
|
|
|
|
, outputs ? [ "out" ]
|
|
|
|
, ...
|
|
|
|
}@args:
|
2021-12-29 02:15:10 +03:00
|
|
|
let
|
|
|
|
defaultValues = {
|
|
|
|
inherit
|
2021-12-29 02:27:49 +03:00
|
|
|
cargoVendorDir
|
2021-12-29 02:15:10 +03:00
|
|
|
doCompressTarget
|
2021-12-29 05:51:06 +03:00
|
|
|
doCopyTargetToOutput
|
|
|
|
doRemapSourcePathPrefix;
|
2021-12-27 03:18:22 +03:00
|
|
|
|
2021-12-29 02:15:10 +03:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
cargo check --release
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
additions = {
|
2021-12-29 02:19:10 +03:00
|
|
|
outputs = outputs ++ lib.optional doCopyTargetToOutput "target";
|
2021-12-29 02:15:10 +03:00
|
|
|
|
|
|
|
nativeBuildInputs = nativeBuildInputs ++ [
|
|
|
|
cargo
|
|
|
|
configureCargoCommonVarsHook
|
|
|
|
configureCargoVendoredDepsHook
|
|
|
|
copyCargoTargetToOutputHook
|
2021-12-29 03:29:31 +03:00
|
|
|
inheritCargoArtifactsHook
|
2021-12-29 04:51:51 +03:00
|
|
|
installFromCargoArtifactsHook
|
2021-12-29 05:51:06 +03:00
|
|
|
remapSourcePathPrefixHook
|
2021-12-29 02:15:10 +03:00
|
|
|
];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation (defaultValues // args // additions)
|