nixpkgs-suyu/pkgs/development/compilers/mint/crystal2nix.cr

36 lines
912 B
Crystal
Raw Normal View History

2018-05-27 21:13:22 +02:00
require "yaml"
2018-05-27 22:41:44 +02:00
require "json"
class PrefetchJSON
JSON.mapping(sha256: String)
end
2018-05-27 21:13:22 +02:00
File.open "shards.nix", "w+" do |file|
2018-05-27 22:41:44 +02:00
file.puts %({)
2018-05-27 21:13:22 +02:00
yaml = YAML.parse(File.read("shard.lock"))
2018-06-17 13:03:47 +02:00
yaml["shards"].as_h.each do |key, value|
2018-05-30 17:54:56 +02:00
owner, repo = value["github"].as_s.split("/")
2018-05-27 22:41:44 +02:00
url = "https://github.com/#{value["github"]}"
rev = if value["version"]?
"v#{value["version"]}"
else
value["commit"].as_s
end
2018-05-27 21:13:22 +02:00
2018-05-27 22:41:44 +02:00
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
2018-05-27 21:13:22 +02:00
end
2018-05-27 22:41:44 +02:00
file.puts %( #{key} = {)
2018-05-30 17:54:56 +02:00
file.puts %( owner = "#{owner}";)
file.puts %( repo = "#{repo}";)
2018-05-27 22:41:44 +02:00
file.puts %( rev = "#{rev}";)
file.puts %( sha256 = "#{sha256}";)
file.puts %( };)
2018-05-27 21:13:22 +02:00
end
2018-05-27 22:41:44 +02:00
file.puts %(})
2018-05-27 21:13:22 +02:00
end