mkCargoDerivation: populate pname and version if not specified

This commit is contained in:
Ivan Petkov 2022-10-09 11:35:26 -07:00
parent d3db2ecf01
commit d4a3bee75f
3 changed files with 10 additions and 2 deletions

View File

@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
reference to a (possibly different) executable in the store.
* `mkCargoDerivation` now automatically vendors dependencies if `cargoVendorDir`
is not defined
* `mkCargoDerivation` now automatically populates `pname` and `version` (via
`crateNameFromCargoToml`) if they are not specified
### Fixed
* Installing binaries now uses the same version of cargo as was used to build

View File

@ -712,7 +712,6 @@ This is a fairly low-level abstraction, so consider using `buildPackage` or
* `checkPhaseCargoCommand`: A command (likely a cargo invocation) to run during
the derivation's check phase. Pre and post check hooks will automatically be
run.
* `pname`: the package name used for the derivation
#### Optional attributes
* `buildPhase`: the commands used by the build phase of the derivation
@ -742,10 +741,14 @@ This is a fairly low-level abstraction, so consider using `buildPackage` or
- By default an output directory is created such that any other `postInstall`
hooks can successfully run. Consider overriding this value with an
appropriate installation commands for the package being built.
* `pname`: the name of the derivation
- Default value: the package name listed in `Cargo.toml`
* `pnameSuffix`: a suffix appended to `pname`
- Default value: `""`
* `stdenv`: the standard build environment to use for this derivation
- Default value: `pkgs.stdenv`
* `version`: the version of the derivation
- Default value: the version listed in `Cargo.toml`
#### Remove attributes
The following attributes will be removed before being lowered to

View File

@ -2,6 +2,7 @@
, cargoHelperFunctionsHook
, configureCargoCommonVarsHook
, configureCargoVendoredDepsHook
, crateNameFromCargoToml
, inheritCargoArtifactsHook
, installCargoArtifactsHook
, lib
@ -26,6 +27,7 @@ args@{
, ...
}:
let
crateName = crateNameFromCargoToml args;
chosenStdenv = args.stdenv or stdenv;
cleanedArgs = builtins.removeAttrs args [
"buildPhaseCargoCommand"
@ -36,7 +38,8 @@ let
];
in
chosenStdenv.mkDerivation (cleanedArgs // {
pname = "${args.pname}${args.pnameSuffix or ""}";
pname = "${args.pname or crateName.pname}${args.pnameSuffix or ""}";
version = args.version or crateName.version;
# Controls whether cargo's `target` directory should be copied as an output
doInstallCargoArtifacts = args.doInstallCargoArtifacts or true;