about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/crystal/crystal2nix.cr
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/crystal/crystal2nix.cr')
-rw-r--r--nixpkgs/pkgs/development/compilers/crystal/crystal2nix.cr42
1 files changed, 42 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/compilers/crystal/crystal2nix.cr b/nixpkgs/pkgs/development/compilers/crystal/crystal2nix.cr
new file mode 100644
index 000000000000..0610de5cfa4d
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/crystal/crystal2nix.cr
@@ -0,0 +1,42 @@
+require "yaml"
+require "json"
+
+class PrefetchJSON
+  JSON.mapping(sha256: String)
+end
+
+class ShardLock
+  YAML.mapping(
+    version: Float32,
+    shards: Hash(String, Hash(String, String))
+  )
+end
+
+File.open "shards.nix", "w+" do |file|
+  file.puts %({)
+  yaml = ShardLock.from_yaml(File.read("shard.lock"))
+  yaml.shards.each do |key, value|
+    owner, repo = value["github"].split("/")
+    url = "https://github.com/#{value["github"]}"
+    rev = if value["version"]?
+            "v#{value["version"]}"
+          else
+            value["commit"]
+          end
+
+    sha256 = ""
+    args = ["--url", url, "--rev", rev]
+    Process.run("@nixPrefetchGit@", 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