cleverca22
12/17/2015 - 4:05 PM

dep-fetcher.sh

  fetchSingleDep = { groupId, artifactId, v, sha256, timestamp, deps, chosen ? "", suffix ? "" }: stdenv.mkDerivation {
    name = lib.replaceChars ["[" "," ")"] ["" "-" ""] "${groupId}-${artifactId}-${v}";
    buildInputs = [ curl ];
    mirrors = [
      "http://repo1.maven.org/maven2"
      "http://files.minecraftforge.net/maven"
      "https://libraries.minecraft.net"
      "http://chickenbones.net/maven"
      "http://klingon.angeldsis.com/maven"
      "http://maven.k-4u.nl"
      "http://maven.cil.li"
      "http://maven.ic2.player.to"
    ];
    DIR1 = "${lib.replaceChars ["."] ["/"] groupId}/${artifactId}" + (if chosen == "" then "/${v}" else "");
    DIR2 = "${lib.replaceChars ["."] ["/"] groupId}/${artifactId}" + (if chosen == "" then "/${v}" else "/${chosen}");
    filename = 
      (if chosen == "" then
        (if timestamp == null then "${artifactId}-${v}" else "${artifactId}-${lib.replaceStrings ["SNAPSHOT"] [timestamp] v}")
      else
        ("${artifactId}-${chosen}")) + suffix;
    inherit timestamp;
    unpackPhase = ":";
    buildPhase = builtins.readFile ./dep-fetcher.sh;
    dontInstall = true;
    outputHashAlgo = "sha256";
    outputHashMode = "recursive";
    outputHash = sha256;
  } // { inherit deps; };


  dependencies = builtins.listToAttrs (map (dep: {
      name = "${dep.groupId}:${dep.artifactId}";
      value = builtins.listToAttrs (map (ver: { name = ver.v; value = fetchSingleDep (ver // {
          inherit (dep) groupId artifactId;
          #version = ver.v; 
          sha256 = if ver.sha256 == "" then "1gwydc5wdm74gaq00b8p7lxs1ck6ry336lmxz0wzjkya2w2fb2ay" else ver.sha256;
          timestamp = if ver ? timestamp then ver.timestamp else null;
          deps = if ver ? deps then ver.deps else [];
        }); }) dep.versions);
    }) (deps dependencies));


  deps = self: [
    { groupId = "com.googlecode.javaewah"; artifactId = "JavaEWAH"; versions = [ {v="0.5.6";sha256="03sl0izv83pvc3yfjayllgk9xy52wlpkmxan66sj3qa583g1p6cz"; deps = [
      self."org.sonatype.oss:oss-parent"."5"
    ]; } ]; }
    { groupId = "net.minecraftforge.gradle"; artifactId = "ForgeGradle"; versions = [
      {v="1.2-SNAPSHOT";timestamp="20150805.153118-302";sha256="0dlbpy0cn9lllx7xg45lsqs3cbjbkisa18p77w1ss3jfxbgyv8yk"; deps = [
        self."net.minecraftforge.srg2source:Srg2Source"."3.2-SNAPSHOT"
        self."org.apache.httpcomponents:httpclient"."4.3.3"
        self."com.google.code.gson:gson"."2.2.4"
        self."com.google.guava:guava"."18.0"
        self."org.apache.httpcomponents:httpmime"."4.3.3"
        self."de.oceanlabs.mcp:mcinjector"."3.2-SNAPSHOT"
        self."de.oceanlabs.mcp:RetroGuard"."3.6.6"
        self."org.eclipse.jdt:org.eclipse.jdt.core"."3.10.0.v20131029-1755"
      ]; }
    ]; }
    { groupId = "de.oceanlabs.mcp"; artifactId = "RetroGuard"; versions = [ { v="3.6.6"; sha256="1shxy207v3q70g46z5sgn1x3m9lm6prfqrlh363a2s0794r0wwl9"; deps = [
      self."net.sf.jopt-simple:jopt-simple"."4.7"
    ];} ]; }
    { groupId = "net.sf.opencsv"; artifactId = "opencsv"; versions = [ { v="2.3"; sha256="1fqp7cqzzw8fjk4iznlgqn7kd4zgnszsc9h5rq6gkyadj8334mdw"; } ]; }
    { groupId = "org.sonatype.oss"; artifactId = "oss-parent"; versions = [
      { v="5"; sha256="14k59b6sqnyc0rpdphqih59xcs42hwkrr8x9sdlsrag9hbzh31d5"; }
      { v="6"; sha256="020c094kapn4gdl8sdp04xypvyi881xrlk5z32dylwh9mbnskxyv"; }
      { v="7"; sha256="0lrb7c0lp4svrzn2qxf88pf9clqcynjkzr9ksll51jns1340zhql"; }
      { v="9"; sha256="17875s32p2mpa5r66g0nlazb7x8fs6x5mnwg8ddd08d9pfp8378z"; }
    ]; }
...
mkdir -pv $out/repository/{$DIR1,$DIR2}
function tryfetch {
  if [ ! -e "$2" ] ; then
    echo trying "$1"
    curl -fk "$1" > "$2" || (echo failed; rm "$2")
  else
    true
  fi
}
for mirror in $mirrors; do
  tryfetch ${mirror}/${DIR2}/${filename}.pom $out/repository/$DIR2/${filename}.pom
  tryfetch ${mirror}/${DIR2}/${filename}.jar $out/repository/$DIR2/${filename}.jar
  tryfetch ${mirror}/${DIR1}/maven-metadata.xml $out/repository/$DIR1/maven-metadata.xml
done
find $out -type f