mirror of
https://github.com/ipetkov/crane.git
synced 2024-11-23 16:32:23 +03:00
25 lines
611 B
Nix
25 lines
611 B
Nix
{ internalCrateNameFromCargoToml
|
|
, lib
|
|
}:
|
|
|
|
input:
|
|
let
|
|
pathArgs = if lib.isAttrs input then input else { path = input; };
|
|
|
|
cargoTomlContents =
|
|
let
|
|
emptyToml = { };
|
|
cargoToml = pathArgs.path + "/Cargo.toml";
|
|
cargoTomlContents = builtins.readFile cargoToml;
|
|
toml = builtins.tryEval (builtins.fromTOML cargoTomlContents);
|
|
in
|
|
if builtins.pathExists cargoToml
|
|
then
|
|
if toml.success then toml.value else emptyToml
|
|
else
|
|
emptyToml;
|
|
|
|
name = (internalCrateNameFromCargoToml cargoTomlContents).pname or "source";
|
|
in
|
|
builtins.path ({ inherit name; } // pathArgs)
|