2022-01-03 01:48:32 +03:00
|
|
|
{ cargo
|
|
|
|
, configureCargoCommonVarsHook
|
|
|
|
, configureCargoVendoredDepsHook
|
|
|
|
, inheritCargoArtifactsHook
|
2022-01-09 04:14:05 +03:00
|
|
|
, installCargoArtifactsHook
|
2022-01-04 20:48:22 +03:00
|
|
|
, lib
|
2022-01-03 01:48:32 +03:00
|
|
|
, remapSourcePathPrefixHook
|
|
|
|
, stdenv
|
|
|
|
}:
|
|
|
|
|
|
|
|
args@{
|
|
|
|
# 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
|
|
|
|
# A directory of vendored cargo sources which can be consumed without network
|
|
|
|
# access. Directory structure should basically follow the output of `cargo vendor`.
|
|
|
|
, cargoVendorDir
|
|
|
|
# A command (likely a cargo invocation) to run during the derivation's build
|
|
|
|
# phase. Pre and post build hooks will automatically be run.
|
|
|
|
, buildPhaseCargoCommand
|
|
|
|
# A command (likely a cargo invocation) to run during the derivation's check
|
|
|
|
# phase. Pre and post check hooks will automatically be run.
|
|
|
|
, checkPhaseCargoCommand
|
2022-01-04 01:39:57 +03:00
|
|
|
# A command to run during the derivation's install
|
2022-01-03 01:48:32 +03:00
|
|
|
# phase. Pre and post install hooks will automatically be run.
|
2022-01-04 01:39:57 +03:00
|
|
|
, installPhaseCommand ? "mkdir -p $out"
|
2022-01-03 01:48:32 +03:00
|
|
|
, ...
|
|
|
|
}:
|
2022-01-05 04:45:31 +03:00
|
|
|
let
|
|
|
|
cleanedArgs = builtins.removeAttrs args [
|
|
|
|
"buildPhaseCargoCommand"
|
|
|
|
"checkPhaseCargoCommand"
|
|
|
|
"installPhaseCommand"
|
|
|
|
"pnameSuffix"
|
|
|
|
];
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation (cleanedArgs // {
|
|
|
|
pname = "${args.pname}${args.pnameSuffix or ""}";
|
|
|
|
|
2022-01-03 01:48:32 +03:00
|
|
|
# Controls whether cargo's `target` directory should be copied as an output
|
2022-01-09 04:14:05 +03:00
|
|
|
doInstallCargoArtifacts = args.doInstallCargoArtifacts or true;
|
2022-01-03 01:48:32 +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.
|
|
|
|
doRemapSourcePathPrefix = args.doRemapSourcePathPrefix or true;
|
|
|
|
|
|
|
|
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
|
|
|
|
cargo
|
|
|
|
configureCargoCommonVarsHook
|
|
|
|
configureCargoVendoredDepsHook
|
|
|
|
inheritCargoArtifactsHook
|
2022-01-09 04:14:05 +03:00
|
|
|
installCargoArtifactsHook
|
2022-01-03 01:48:32 +03:00
|
|
|
remapSourcePathPrefixHook
|
|
|
|
];
|
|
|
|
|
|
|
|
buildPhase = args.buildPhase or ''
|
|
|
|
runHook preBuild
|
2022-01-08 07:48:52 +03:00
|
|
|
cargo --version
|
2022-01-04 20:48:22 +03:00
|
|
|
echo running: ${lib.strings.escapeShellArg buildPhaseCargoCommand}
|
2022-01-03 01:48:32 +03:00
|
|
|
${buildPhaseCargoCommand}
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
checkPhase = args.checkPhase or ''
|
|
|
|
runHook preCheck
|
2022-01-04 20:48:22 +03:00
|
|
|
echo running: ${lib.strings.escapeShellArg checkPhaseCargoCommand}
|
2022-01-03 01:48:32 +03:00
|
|
|
${checkPhaseCargoCommand}
|
|
|
|
runHook postCheck
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = args.installPhase or ''
|
|
|
|
runHook preInstall
|
2022-01-04 20:48:22 +03:00
|
|
|
echo running: ${lib.strings.escapeShellArg installPhaseCommand}
|
2022-01-04 01:39:57 +03:00
|
|
|
${installPhaseCommand}
|
2022-01-03 01:48:32 +03:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
})
|