Parse lockfile for expanded revision

This commit is contained in:
Tony Olagbaiye 2020-03-23 07:50:12 +00:00 committed by Nicolas Mattia
parent 8ca2512256
commit c55558b630
2 changed files with 10 additions and 2 deletions

View file

@ -46,7 +46,7 @@ let
let
config = mkConfig arg;
gitDependencies =
libb.findGitDependencies { inherit (config) cargotomls; };
libb.findGitDependencies { inherit (config) cargotomls cargolock; };
in
import ./build.nix
(

10
lib.nix
View file

@ -76,6 +76,7 @@ rec
# }
findGitDependencies =
{ cargotomls
, cargolock
}:
let
tomlDependencies = cargotoml:
@ -92,7 +93,14 @@ rec
checkout = builtins.fetchGit ({
url = v.git;
} // lib.optionalAttrs (v ? rev) {
rev = v.rev;
rev = let
query = p: p.name == k && (lib.substring 0 (4 + lib.stringLength v.git) p.source) == "git+${v.git}";
extractRevision = url: lib.last (lib.splitString "#" url);
parseLock = lock: rec { inherit (lock) name source; revision = extractRevision source; };
packageLocks = builtins.map parseLock (lib.filter query cargolock.package);
match = lib.findFirst (p: lib.substring 0 7 p.revision == lib.substring 0 7 v.rev) null packageLocks;
in
if ! (isNull match) then match.revision else v.rev;
} // lib.optionalAttrs (v ? branch) {
ref = v.branch;
} // lib.optionalAttrs (v ? tag) {