From d4a3bee75f042f598862340b42d51203be1e69c4 Mon Sep 17 00:00:00 2001 From: Ivan Petkov Date: Sun, 9 Oct 2022 11:35:26 -0700 Subject: [PATCH] mkCargoDerivation: populate pname and version if not specified --- CHANGELOG.md | 2 ++ docs/API.md | 5 ++++- lib/mkCargoDerivation.nix | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cbddef..48ac2ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/API.md b/docs/API.md index 81eef48..4182232 100644 --- a/docs/API.md +++ b/docs/API.md @@ -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 diff --git a/lib/mkCargoDerivation.nix b/lib/mkCargoDerivation.nix index a6dd504..99f21fd 100644 --- a/lib/mkCargoDerivation.nix +++ b/lib/mkCargoDerivation.nix @@ -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;