Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve registry and git based dependencies #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve git deps parsing
  • Loading branch information
Mifom committed Mar 31, 2022
commit eccab1a17098cdd7b04783d39d0da737a2561cba
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