mirror of
https://github.com/tadfisher/gradle2nix.git
synced 2026-01-11 15:30:38 -05:00
gradle-env.nix: Support fetchers per URL scheme
This commit is contained in:
@@ -19,7 +19,15 @@
|
|||||||
# '';
|
# '';
|
||||||
# }
|
# }
|
||||||
|
|
||||||
{ stdenv, buildEnv, fetchurl, gradleGen, writeText, writeTextDir }:
|
{ lib
|
||||||
|
, stdenv
|
||||||
|
, buildEnv
|
||||||
|
, fetchs3
|
||||||
|
, fetchurl
|
||||||
|
, gradleGen
|
||||||
|
, writeText
|
||||||
|
, writeTextDir
|
||||||
|
}:
|
||||||
|
|
||||||
{
|
{
|
||||||
# Path to the environment spec generated by gradle2nix (e.g. gradle-env.json).
|
# Path to the environment spec generated by gradle2nix (e.g. gradle-env.json).
|
||||||
@@ -38,29 +46,68 @@
|
|||||||
, extraInit ? ""
|
, extraInit ? ""
|
||||||
# Override the default JDK used to run Gradle itself.
|
# Override the default JDK used to run Gradle itself.
|
||||||
, buildJdk ? null
|
, buildJdk ? null
|
||||||
|
# Override functions which fetch dependency artifacts.
|
||||||
|
# Keys in this set are URL schemes such as "https" or "s3".
|
||||||
|
# Values are functions which take a dependency in the form
|
||||||
|
# `{ urls, sha256 }` and fetch into the Nix store. For example:
|
||||||
|
#
|
||||||
|
# {
|
||||||
|
# s3 = { urls, sha256 }: fetchs3 {
|
||||||
|
# s3url = builtins.head urls;
|
||||||
|
# inherit sha256;
|
||||||
|
# region = "us-west-2";
|
||||||
|
# credentials = {
|
||||||
|
# access_key_id = "foo";
|
||||||
|
# secret_access_key = "bar";
|
||||||
|
# };
|
||||||
|
# };
|
||||||
|
# }
|
||||||
|
, fetchers ? { }
|
||||||
, ... } @ args:
|
, ... } @ args:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (builtins)
|
inherit (builtins)
|
||||||
attrValues concatStringsSep filter fromJSON match replaceStrings sort;
|
attrValues concatStringsSep filter fromJSON getAttr head match
|
||||||
|
replaceStrings sort;
|
||||||
|
|
||||||
inherit (stdenv.lib)
|
inherit (lib)
|
||||||
assertMsg concatMapStringsSep groupBy' hasSuffix last mapAttrs
|
assertMsg concatMapStringsSep groupBy' hasSuffix hasPrefix last mapAttrs
|
||||||
mapAttrsToList optionalString readFile removeSuffix unique versionAtLeast
|
mapAttrsToList optionalString readFile removeSuffix unique versionAtLeast
|
||||||
versionOlder;
|
versionOlder;
|
||||||
|
|
||||||
mkDep = depSpec: stdenv.mkDerivation {
|
fetchers' = {
|
||||||
inherit (depSpec) name;
|
http = fetchurl;
|
||||||
|
https = fetchurl;
|
||||||
|
s3 = { urls, sha256 }: fetchs3 {
|
||||||
|
s3url = head urls;
|
||||||
|
inherit sha256;
|
||||||
|
};
|
||||||
|
} // fetchers;
|
||||||
|
|
||||||
src = fetchurl {
|
# Fetch urls using the scheme for the first entry only; there isn't a
|
||||||
inherit (depSpec) urls sha256;
|
# straightforward way to tell Nix to try multiple fetchers in turn
|
||||||
|
# and short-circuit on the first successful fetch.
|
||||||
|
fetch = { urls, sha256 }:
|
||||||
|
let
|
||||||
|
first = head urls;
|
||||||
|
scheme = head (builtins.match "([a-z0-9+.-]+)://.*" first);
|
||||||
|
fetch' = getAttr scheme fetchers';
|
||||||
|
urls' = filter (hasPrefix scheme) urls;
|
||||||
|
in
|
||||||
|
fetch' { urls = urls'; inherit sha256; };
|
||||||
|
|
||||||
|
mkDep = { name, path, urls, sha256, ... }: stdenv.mkDerivation {
|
||||||
|
inherit name;
|
||||||
|
|
||||||
|
src = fetch {
|
||||||
|
inherit urls sha256;
|
||||||
};
|
};
|
||||||
|
|
||||||
phases = "installPhase";
|
phases = "installPhase";
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p $out/${depSpec.path}
|
mkdir -p $out/${path}
|
||||||
ln -s $src $out/${depSpec.path}/${depSpec.name}
|
ln -s $src $out/${path}/${name}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user