mirror of
https://github.com/SebastianWendel/nixpkgs.git
synced 2024-09-20 04:19:00 +02:00
rustPlatform.importCargoLock: add allowBuiltinFetchGit option
This commit is contained in:
parent
4516b17cf4
commit
cce3dc63a0
|
@ -186,6 +186,23 @@ added. To find the correct hash, you can first use `lib.fakeSha256` or
|
||||||
`lib.fakeHash` as a stub hash. Building the package (and thus the
|
`lib.fakeHash` as a stub hash. Building the package (and thus the
|
||||||
vendored dependencies) will then inform you of the correct hash.
|
vendored dependencies) will then inform you of the correct hash.
|
||||||
|
|
||||||
|
For usage outside nixpkgs, `allowBuiltinFetchGit` could be used to
|
||||||
|
avoid having to specify `outputHashes`. For example:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
rustPlatform.buildRustPackage rec {
|
||||||
|
pname = "myproject";
|
||||||
|
version = "1.0.0";
|
||||||
|
|
||||||
|
cargoLock = {
|
||||||
|
lockFile = ./Cargo.lock;
|
||||||
|
allowBuiltinFetchGit = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
# ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Cargo features {#cargo-features}
|
### Cargo features {#cargo-features}
|
||||||
|
|
||||||
You can disable default features using `buildNoDefaultFeatures`, and
|
You can disable default features using `buildNoDefaultFeatures`, and
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
# Cargo lock file contents as string
|
# Cargo lock file contents as string
|
||||||
, lockFileContents ? null
|
, lockFileContents ? null
|
||||||
|
|
||||||
|
# Allow `builtins.fetchGit` to be used to not require hashes for git dependencies
|
||||||
|
, allowBuiltinFetchGit ? false
|
||||||
|
|
||||||
# Hashes for git dependencies.
|
# Hashes for git dependencies.
|
||||||
, outputHashes ? {}
|
, outputHashes ? {}
|
||||||
} @ args:
|
} @ args:
|
||||||
|
@ -38,14 +41,14 @@ let
|
||||||
# There is no source attribute for the source package itself. But
|
# There is no source attribute for the source package itself. But
|
||||||
# since we do not want to vendor the source package anyway, we can
|
# since we do not want to vendor the source package anyway, we can
|
||||||
# safely skip it.
|
# safely skip it.
|
||||||
depPackages = (builtins.filter (p: p ? "source") packages);
|
depPackages = builtins.filter (p: p ? "source") packages;
|
||||||
|
|
||||||
# Create dependent crates from packages.
|
# Create dependent crates from packages.
|
||||||
#
|
#
|
||||||
# Force evaluation of the git SHA -> hash mapping, so that an error is
|
# Force evaluation of the git SHA -> hash mapping, so that an error is
|
||||||
# thrown if there are stale hashes. We cannot rely on gitShaOutputHash
|
# thrown if there are stale hashes. We cannot rely on gitShaOutputHash
|
||||||
# being evaluated otherwise, since there could be no git dependencies.
|
# being evaluated otherwise, since there could be no git dependencies.
|
||||||
depCrates = builtins.deepSeq (gitShaOutputHash) (builtins.map mkCrate depPackages);
|
depCrates = builtins.deepSeq gitShaOutputHash (builtins.map mkCrate depPackages);
|
||||||
|
|
||||||
# Map package name + version to git commit SHA for packages with a git source.
|
# Map package name + version to git commit SHA for packages with a git source.
|
||||||
namesGitShas = builtins.listToAttrs (
|
namesGitShas = builtins.listToAttrs (
|
||||||
|
@ -117,12 +120,20 @@ let
|
||||||
If you use `buildRustPackage`, you can add this attribute to the `cargoLock`
|
If you use `buildRustPackage`, you can add this attribute to the `cargoLock`
|
||||||
attribute set.
|
attribute set.
|
||||||
'';
|
'';
|
||||||
sha256 = gitShaOutputHash.${gitParts.sha} or missingHash;
|
tree =
|
||||||
tree = fetchgit {
|
if gitShaOutputHash ? ${gitParts.sha} then
|
||||||
inherit sha256;
|
fetchgit {
|
||||||
inherit (gitParts) url;
|
inherit (gitParts) url;
|
||||||
rev = gitParts.sha; # The commit SHA is always available.
|
rev = gitParts.sha; # The commit SHA is always available.
|
||||||
};
|
sha256 = gitShaOutputHash.${gitParts.sha};
|
||||||
|
}
|
||||||
|
else if allowBuiltinFetchGit then
|
||||||
|
builtins.fetchGit {
|
||||||
|
inherit (gitParts) url;
|
||||||
|
rev = gitParts.sha;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
missingHash;
|
||||||
in runCommand "${pkg.name}-${pkg.version}" {} ''
|
in runCommand "${pkg.name}-${pkg.version}" {} ''
|
||||||
tree=${tree}
|
tree=${tree}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue