summary refs log tree commit diff
path: root/pkgs/development/compilers/mint/crystal2nix.cr
blob: f2ef5dafdbc33230a517b982400d825988664cb5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require "yaml"
require "json"

class PrefetchJSON
  JSON.mapping(sha256: String)
end

File.open "shards.nix", "w+" do |file|
  file.puts %({)
  yaml = YAML.parse(File.read("shard.lock"))
  yaml["shards"].as_h.each do |key, value|
    owner, repo = value["github"].as_s.split("/")
    url = "https://github.com/#{value["github"]}"
    rev = if value["version"]?
            "v#{value["version"]}"
          else
            value["commit"].as_s
          end

    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 %(  #{key} = {)
    file.puts %(    owner = "#{owner}";)
    file.puts %(    repo = "#{repo}";)
    file.puts %(    rev = "#{rev}";)
    file.puts %(    sha256 = "#{sha256}";)
    file.puts %(  };)
  end
  file.puts %(})
end