Skip to content

Commit

Permalink
Improve git deps parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Mifom committed Mar 31, 2022
1 parent 149164a commit eccab1a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@
(pkg:

let
isGit = builtins.match ''git\+(.*)\?rev=([0-9a-f]+)(#.*)?'' pkg.source;
gitRegexp = x: builtins.match "git\+(.*)\?((branch=(.+)#([0-9a-f]+)(#.*)?)|(rev=([0-9a-f]+)(#.*)?))" x;
isGit = let gitArr = gitRegexp pkg.source; in
if isNull gitArr then
null
else
let url_ = builtins.elemAt gitArr 0;
url = builtins.substring 1 (builtins.stringLength url_ - 2) url_;
rev4 = builtins.elemAt gitArr 3;
rev5 = builtins.elemAt gitArr 4;
rev8 = builtins.elemAt gitArr 7;
in if isNull rev4 then [url null rev8] else [url rev4 rev5];
isRegistry = builtins.match ''registry\+(.*)'' pkg.source;
in

Expand All @@ -42,7 +52,8 @@

else if isGit != null then
let
rev = builtins.elemAt isGit 1;
rev = builtins.elemAt isGit 2;
branch = builtins.elemAt isGit 1;
url = builtins.elemAt isGit 0;
tree = builtins.fetchGit {
inherit url rev;
Expand All @@ -65,8 +76,9 @@
printf '{"files":{},"package":null}' > "$out/.cargo-checksum.json"
cat > $out/.cargo-config <<EOF
[source."${url}"]
[source."${url}${if isNull branch then "" else "?branch=${branch}"}"]
git = "${url}"
${if isNull branch then "" else "branch = \"${branch}\""}
rev = "${rev}"
replace-with = "vendored-sources"
EOF
Expand Down

0 comments on commit eccab1a

Please sign in to comment.