diff options
Diffstat (limited to 'pkgs/development/compilers/mint/crystal2nix.cr')
-rw-r--r-- | pkgs/development/compilers/mint/crystal2nix.cr | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/pkgs/development/compilers/mint/crystal2nix.cr b/pkgs/development/compilers/mint/crystal2nix.cr index 2ec8c92be3fb7..5d92ae4afeaec 100644 --- a/pkgs/development/compilers/mint/crystal2nix.cr +++ b/pkgs/development/compilers/mint/crystal2nix.cr @@ -1,27 +1,33 @@ require "yaml" +require "json" + +class PrefetchJSON + JSON.mapping(sha256: String) +end File.open "shards.nix", "w+" do |file| - file.puts "{" + file.puts %({) yaml = YAML.parse(File.read("shard.lock")) yaml["shards"].each do |key, value| - file.puts " #{key} = {" - file.puts %( url = "https://github.com/#{value["github"]}";) - if value["commit"]? - file.puts %( rev = "#{value["commit"]}";) - else - url = "https://github.com/#{value["github"]}" - ref = "v#{value["version"]}" - - puts "git ls-remote #{url} #{ref}" - Process.run("git", args: ["ls-remote", url, ref]) do |x| - x.error.each_line { |e| puts e } - x.output.each_line { |o| value.as_h["commit"] = o.split("\t")[0] } - end + url = "https://github.com/#{value["github"]}" + rev = if value["version"]? + "v#{value["version"]}" + else + value["commit"].as_s + end - file.puts %( rev = "#{value["commit"]};) + sha256 = "" + args = ["--url", url, "--rev", rev] + Process.run("nix-prefetch-git", args: args) do |x| + x.error.each_line { |e| puts e } + sha256 = PrefetchJSON.from_json(x.output).sha256 end - file.puts " };" + file.puts %( #{key} = {) + file.puts %( url = "#{url}";) + file.puts %( rev = "#{rev}";) + file.puts %( sha256 = "#{sha256}";) + file.puts %( };) end - file.puts "}" + file.puts %(}) end |