Update crateNameFromCargoToml with better fallback error messages

* If a derivation is created without a name *and* we cannot infer a name
  from a Cargo.toml file, we'll throw a descriptive error message which
  hints towards the remediation
* Otherwise nix can throw a pretty obtuse "derivation has no name" error
  with no error trace
This commit is contained in:
Ivan Petkov 2021-12-30 15:08:45 -08:00
parent 0aadea3b08
commit 2a14c2d53b
No known key found for this signature in database
GPG Key ID: BB6F9EFC065832B6

View File

@ -2,12 +2,24 @@
{ src ? null { src ? null
, cargoToml ? src + /Cargo.toml , cargoToml ? src + /Cargo.toml
, cargoTomlContents ? builtins.readFile cargoToml , cargoTomlContents ? null
, ... , ...
}: }:
if cargoTomlContents == null && (src == null || !builtins.pathExists cargoToml)
then
throw ''
unable to infer crate name and version. Please make sure the src directory
contains a valid Cargo.toml file, or consider setting a derivation name explicitly
''
else
let let
toml = fromTOML cargoTomlContents; cargoTomlRealContents =
if cargoTomlContents != null
then cargoTomlContents
else builtins.readFile cargoToml;
toml = fromTOML cargoTomlRealContents;
p = toml.package; p = toml.package;
in in
{ {