# generated by zon2nix (https://github.com/Cloudef/zig2nix)

{ lib, linkFarm, fetchurl, fetchgit, runCommandLocal, zig, name ? "zig-packages" }:

with builtins;
with lib;

let
  unpackZigArtifact = { name, artifact }: runCommandLocal name {
      nativeBuildInputs = [ zig ];
    } ''
      hash="$(zig fetch --global-cache-dir "$TMPDIR" ${artifact})"
      mv "$TMPDIR/p/$hash" "$out"
      chmod 755 "$out"
    '';

  fetchZig = { name, url, hash }: let
    artifact = fetchurl { inherit url hash; };
  in unpackZigArtifact { inherit name artifact; };

  fetchGitZig = { name, url, hash }: let
    parts = splitString "#" url;
    url_base = elemAt parts 0;
    url_without_query = elemAt (splitString "?" url_base) 0;
    rev_base = elemAt parts 1;
    rev = if match "^[a-fA-F0-9]{40}$" rev_base != null then rev_base else "refs/heads/${rev_base}";
  in fetchgit {
    inherit name rev hash;
    url = url_without_query;
    deepClone = false;
  };

  fetchZigArtifact = { name, url, hash }: let
    parts = splitString "://" url;
    proto = elemAt parts 0;
    path = elemAt parts 1;
    fetcher = {
      "git+http" = fetchGitZig { inherit name hash; url = "http://${path}"; };
      "git+https" = fetchGitZig { inherit name hash; url = "https://${path}"; };
      http = fetchZig { inherit name hash; url = "http://${path}"; };
      https = fetchZig { inherit name hash; url = "https://${path}"; };
      file = unpackZigArtifact { inherit name; artifact = /. + path; };
    };
  in fetcher.${proto};
in linkFarm name [
  {
    name = "12204a223b19043e17b79300413d02f60fc8004c0d9629b8d8072831e352a78bf212";
    path = fetchZigArtifact {
      name = "raylib-zig";
      url = "https://github.com/Not-Nik/raylib-zig/archive/43d15b05c2b97cab30103fa2b46cff26e91619ec.tar.gz";
      hash = "sha256-4SQd50vIK9XWMyuj/ymclmvj39BX4dp6ueFrgaEwRYM=";
    };
  }
  {
    name = "1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26";
    path = fetchZigArtifact {
      name = "raylib";
      url = "https://github.com/raysan5/raylib/archive/5767c4cd059e07355ae5588966d0aee97038a86b.tar.gz";
      hash = "sha256-ijvgBlAfUD71p07Zg/oMzZnneQ95RoiaJXIkNlB26oc=";
    };
  }
  {
    name = "122002d98ca255ec706ef8e5497b3723d6c6e163511761d116dac3aee87747d46cf1";
    path = fetchZigArtifact {
      name = "raygui";
      url = "https://github.com/raysan5/raygui/archive/4b3d94f5df6a5a2aa86286350f7e20c0ca35f516.tar.gz";
      hash = "sha256-AjU+fyonXnGTG8ZBMb10ScB3G6iI97eiL9N3anm+r1Q=";
    };
  }
  {
    name = "1220d2cf253817dd18c8486336b68b465e7c98268d3c5449df81736f42d7be0870a8";
    path = fetchZigArtifact {
      name = "s2s";
      url = "https://github.com/Deecellar/s2s/archive/4314e9bd2a50cbfd497868a66d758464eefe5076.tar.gz";
      hash = "sha256-3d4O2roswVE62i2PMdik7fea5Rdc0ogDtcHUx9VUiM4=";
    };
  }
]