2018-05-27 20:13:22 +01:00
|
|
|
require "yaml"
|
2018-05-27 21:41:44 +01:00
|
|
|
require "json"
|
|
|
|
|
|
|
|
class PrefetchJSON
|
|
|
|
JSON.mapping(sha256: String)
|
|
|
|
end
|
2018-05-27 20:13:22 +01:00
|
|
|
|
2018-07-06 10:32:08 +01:00
|
|
|
class ShardLock
|
|
|
|
YAML.mapping(
|
2018-07-31 15:54:37 +01:00
|
|
|
version: Float32,
|
2018-07-06 10:32:08 +01:00
|
|
|
shards: Hash(String, Hash(String, String))
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-05-27 20:13:22 +01:00
|
|
|
File.open "shards.nix", "w+" do |file|
|
2018-05-27 21:41:44 +01:00
|
|
|
file.puts %({)
|
2018-07-06 10:32:08 +01:00
|
|
|
yaml = ShardLock.from_yaml(File.read("shard.lock"))
|
|
|
|
yaml.shards.each do |key, value|
|
|
|
|
owner, repo = value["github"].split("/")
|
2018-05-27 21:41:44 +01:00
|
|
|
url = "https://github.com/#{value["github"]}"
|
|
|
|
rev = if value["version"]?
|
|
|
|
"v#{value["version"]}"
|
|
|
|
else
|
2018-07-06 10:32:08 +01:00
|
|
|
value["commit"]
|
2018-05-27 21:41:44 +01:00
|
|
|
end
|
2018-05-27 20:13:22 +01:00
|
|
|
|
2018-05-27 21:41:44 +01: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 20:13:22 +01:00
|
|
|
end
|
|
|
|
|
2018-05-27 21:41:44 +01:00
|
|
|
file.puts %( #{key} = {)
|
2018-05-30 16:54:56 +01:00
|
|
|
file.puts %( owner = "#{owner}";)
|
|
|
|
file.puts %( repo = "#{repo}";)
|
2018-05-27 21:41:44 +01:00
|
|
|
file.puts %( rev = "#{rev}";)
|
|
|
|
file.puts %( sha256 = "#{sha256}";)
|
|
|
|
file.puts %( };)
|
2018-05-27 20:13:22 +01:00
|
|
|
end
|
2018-05-27 21:41:44 +01:00
|
|
|
file.puts %(})
|
2018-05-27 20:13:22 +01:00
|
|
|
end
|