diff options
author | figsoda <figsoda@pm.me> | 2022-12-13 11:22:07 -0500 |
---|---|---|
committer | figsoda <figsoda@pm.me> | 2022-12-13 11:27:26 -0500 |
commit | cce3dc63a02b34d61326dc155a933a91d6937ccc (patch) | |
tree | 6784af9c17fd50aee99fbe0eda8d1675631ce981 /pkgs/build-support/rust/import-cargo-lock.nix | |
parent | 4516b17cf45931b5b47188f9a47e11359eaf5b09 (diff) | |
download | nixpkgs-cce3dc63a02b34d61326dc155a933a91d6937ccc.tar nixpkgs-cce3dc63a02b34d61326dc155a933a91d6937ccc.tar.gz nixpkgs-cce3dc63a02b34d61326dc155a933a91d6937ccc.tar.bz2 nixpkgs-cce3dc63a02b34d61326dc155a933a91d6937ccc.tar.lz nixpkgs-cce3dc63a02b34d61326dc155a933a91d6937ccc.tar.xz nixpkgs-cce3dc63a02b34d61326dc155a933a91d6937ccc.tar.zst nixpkgs-cce3dc63a02b34d61326dc155a933a91d6937ccc.zip |
rustPlatform.importCargoLock: add allowBuiltinFetchGit option
Diffstat (limited to 'pkgs/build-support/rust/import-cargo-lock.nix')
-rw-r--r-- | pkgs/build-support/rust/import-cargo-lock.nix | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/pkgs/build-support/rust/import-cargo-lock.nix b/pkgs/build-support/rust/import-cargo-lock.nix index e571c01f95c..7a4ddec3ebd 100644 --- a/pkgs/build-support/rust/import-cargo-lock.nix +++ b/pkgs/build-support/rust/import-cargo-lock.nix @@ -7,6 +7,9 @@ # Cargo lock file contents as string , lockFileContents ? null + # Allow `builtins.fetchGit` to be used to not require hashes for git dependencies +, allowBuiltinFetchGit ? false + # Hashes for git dependencies. , outputHashes ? {} } @ args: @@ -38,14 +41,14 @@ let # There is no source attribute for the source package itself. But # since we do not want to vendor the source package anyway, we can # safely skip it. - depPackages = (builtins.filter (p: p ? "source") packages); + depPackages = builtins.filter (p: p ? "source") packages; # Create dependent crates from packages. # # Force evaluation of the git SHA -> hash mapping, so that an error is # thrown if there are stale hashes. We cannot rely on gitShaOutputHash # 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. namesGitShas = builtins.listToAttrs ( @@ -117,12 +120,20 @@ let If you use `buildRustPackage`, you can add this attribute to the `cargoLock` attribute set. ''; - sha256 = gitShaOutputHash.${gitParts.sha} or missingHash; - tree = fetchgit { - inherit sha256; - inherit (gitParts) url; - rev = gitParts.sha; # The commit SHA is always available. - }; + tree = + if gitShaOutputHash ? ${gitParts.sha} then + fetchgit { + inherit (gitParts) url; + 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}" {} '' tree=${tree} |