2022-03-28 07:06:08 +01:00
|
|
|
{
|
|
|
|
javaVersion,
|
|
|
|
graalVersion,
|
|
|
|
config,
|
|
|
|
sourcesFilename,
|
|
|
|
lib,
|
|
|
|
writeScript,
|
|
|
|
jq,
|
|
|
|
runtimeShell
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2022-03-29 11:36:39 +01:00
|
|
|
productJavaVersionGraalVersionSep = "|";
|
2022-03-28 07:06:08 +01:00
|
|
|
# getArchString :: String -> String
|
|
|
|
getArchString = nixArchString:
|
|
|
|
{
|
|
|
|
"aarch64-linux" = "linux-aarch64";
|
|
|
|
"x86_64-linux" = "linux-amd64";
|
|
|
|
"x86_64-darwin" = "darwin-amd64";
|
|
|
|
}.${nixArchString};
|
|
|
|
|
|
|
|
|
|
|
|
# getProductSuffix :: String -> String
|
|
|
|
getProductSuffix = productName:
|
2022-03-29 11:36:39 +01:00
|
|
|
{
|
2022-03-28 07:06:08 +01:00
|
|
|
"graalvm-ce" = ".tar.gz";
|
|
|
|
"native-image-installable-svm" = ".jar";
|
|
|
|
"ruby-installable-svm" = ".jar";
|
|
|
|
"wasm-installable-svm" = ".jar";
|
|
|
|
"python-installable-svm" = ".jar";
|
2022-03-29 11:36:39 +01:00
|
|
|
}.${productName};
|
2022-03-28 07:06:08 +01:00
|
|
|
|
|
|
|
# getProductSuffix :: String -> String
|
|
|
|
getProductBaseUrl = productName:
|
2022-03-29 11:36:39 +01:00
|
|
|
{
|
2022-03-28 07:06:08 +01:00
|
|
|
"graalvm-ce" = "https://github.com/graalvm/graalvm-ce-builds/releases/download";
|
|
|
|
"native-image-installable-svm" = "https://github.com/graalvm/graalvm-ce-builds/releases/download";
|
|
|
|
"ruby-installable-svm" = "https://github.com/oracle/truffleruby/releases/download";
|
|
|
|
"wasm-installable-svm" = "https://github.com/graalvm/graalvm-ce-builds/releases/download";
|
|
|
|
"python-installable-svm" = "https://github.com/graalvm/graalpython/releases/download";
|
2022-03-29 11:36:39 +01:00
|
|
|
}.${productName};
|
|
|
|
|
|
|
|
# getDevUrl :: String
|
|
|
|
getDevUrl = { arch, graalVersion, product, javaVersion }:
|
|
|
|
let
|
|
|
|
baseUrl = https://github.com/graalvm/graalvm-ce-dev-builds/releases/download;
|
2022-03-28 07:06:08 +01:00
|
|
|
in
|
2022-03-29 11:36:39 +01:00
|
|
|
"${baseUrl}/${graalVersion}/${product}-${javaVersion}-${arch}-dev${getProductSuffix product}";
|
2022-03-28 07:06:08 +01:00
|
|
|
|
2022-03-29 11:36:39 +01:00
|
|
|
# getReleaseUrl :: AttrSet -> String
|
|
|
|
getReleaseUrl = { arch, graalVersion, product, javaVersion }:
|
|
|
|
let baseUrl = getProductBaseUrl product;
|
|
|
|
in
|
|
|
|
"${baseUrl}/vm-${graalVersion}/${product}-${javaVersion}-${arch}-${graalVersion}${getProductSuffix product}";
|
2022-03-28 07:06:08 +01:00
|
|
|
|
2022-03-29 11:36:39 +01:00
|
|
|
# getUrl :: AttrSet -> String
|
|
|
|
getUrl = args@{ arch, graalVersion, product, javaVersion }:
|
|
|
|
if lib.hasInfix "dev" graalVersion
|
|
|
|
then getDevUrl args
|
|
|
|
else getReleaseUrl args;
|
2022-03-28 07:06:08 +01:00
|
|
|
|
2022-03-29 11:36:39 +01:00
|
|
|
# computeSha256 :: String -> String
|
|
|
|
computeSha256 = url:
|
|
|
|
builtins.hashFile "sha256" (builtins.fetchurl url);
|
|
|
|
|
|
|
|
# downloadSha256 :: String -> String
|
|
|
|
downloadSha256 = url:
|
|
|
|
let sha256Url = url + ".sha256";
|
2022-03-28 07:06:08 +01:00
|
|
|
in
|
2022-03-29 11:36:39 +01:00
|
|
|
builtins.readFile (builtins.fetchurl sha256Url);
|
|
|
|
|
|
|
|
# getSha256 :: String -> String -> String
|
|
|
|
getSha256 = graalVersion: url:
|
|
|
|
if lib.hasInfix "dev" graalVersion
|
|
|
|
then computeSha256 url
|
|
|
|
else downloadSha256 url;
|
2022-03-28 07:06:08 +01:00
|
|
|
|
|
|
|
# cartesianZipListsWith :: (a -> b -> c) -> [a] -> [b] -> [c]
|
|
|
|
cartesianZipListsWith = f: fst: snd:
|
|
|
|
let cartesianProduct = lib.cartesianProductOfSets { a = fst; b = snd; };
|
|
|
|
fst' = builtins.catAttrs "a" cartesianProduct;
|
|
|
|
snd' = builtins.catAttrs "b" cartesianProduct;
|
|
|
|
in
|
|
|
|
lib.zipListsWith f fst' snd';
|
|
|
|
|
|
|
|
# zipListsToAttrs :: [a] -> [b] -> AttrSet
|
|
|
|
zipListsToAttrs = names: values:
|
|
|
|
lib.listToAttrs (
|
|
|
|
lib.zipListsWith (name: value: { inherit name value; }) names values
|
|
|
|
);
|
|
|
|
|
|
|
|
# genProductJavaVersionGraalVersionAttrSet :: String -> AttrSet
|
|
|
|
genProductJavaVersionGraalVersionAttrSet = product_javaVersion_graalVersion:
|
|
|
|
let attrNames = [ "product" "javaVersion" "graalVersion" ];
|
2022-03-29 11:36:39 +01:00
|
|
|
attrValues = lib.splitString productJavaVersionGraalVersionSep product_javaVersion_graalVersion;
|
2022-03-28 07:06:08 +01:00
|
|
|
in zipListsToAttrs attrNames attrValues;
|
|
|
|
|
|
|
|
# genUrlAndSha256 :: String -> String -> AttrSet
|
|
|
|
genUrlAndSha256 = arch: product_javaVersion_graalVersion:
|
|
|
|
let
|
|
|
|
productJavaVersionGraalVersion =
|
|
|
|
(genProductJavaVersionGraalVersionAttrSet product_javaVersion_graalVersion)
|
|
|
|
// { inherit arch; };
|
2022-03-29 11:36:39 +01:00
|
|
|
url = getUrl productJavaVersionGraalVersion;
|
|
|
|
sha256 = getSha256 productJavaVersionGraalVersion.graalVersion url;
|
2022-03-28 07:06:08 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
${arch} = {
|
|
|
|
${product_javaVersion_graalVersion} = {
|
|
|
|
inherit sha256 url;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# genArchProductVersionPairs :: String -> AttrSet -> [AttrSet]
|
|
|
|
genArchProductVersionList = javaGraalVersion: archProducts:
|
|
|
|
let
|
|
|
|
arch = archProducts.arch;
|
|
|
|
products = archProducts.products;
|
|
|
|
productJavaGraalVersionList =
|
2022-03-29 11:36:39 +01:00
|
|
|
cartesianZipListsWith (a: b: a + productJavaVersionGraalVersionSep + b)
|
|
|
|
products [ javaGraalVersion ];
|
2022-03-28 07:06:08 +01:00
|
|
|
in
|
|
|
|
cartesianZipListsWith (genUrlAndSha256) [ arch ] productJavaGraalVersionList;
|
|
|
|
|
|
|
|
|
|
|
|
# genSources :: String -> String -> AttrSet -> Path String
|
|
|
|
genSources = graalVersion: javaVersion: config:
|
|
|
|
let
|
2022-03-29 11:36:39 +01:00
|
|
|
javaGraalVersion = javaVersion + productJavaVersionGraalVersionSep + graalVersion;
|
2022-03-28 07:06:08 +01:00
|
|
|
archProducts = builtins.attrValues config;
|
|
|
|
sourcesList = builtins.concatMap (genArchProductVersionList javaGraalVersion) archProducts;
|
|
|
|
sourcesAttr = builtins.foldl' (lib.recursiveUpdate) {} sourcesList;
|
|
|
|
in
|
|
|
|
builtins.toFile "sources.json" (builtins.toJSON sourcesAttr);
|
|
|
|
|
|
|
|
sourcesJson = genSources graalVersion javaVersion config;
|
|
|
|
|
|
|
|
in
|
|
|
|
writeScript "update-graal.sh" ''
|
|
|
|
#!${runtimeShell}
|
|
|
|
set -o errexit
|
|
|
|
set -o nounset
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
export PATH="${lib.makeBinPath [ jq ]}:$PATH"
|
|
|
|
|
|
|
|
jq . ${sourcesJson} > ${lib.strings.escapeShellArg ./.}/${sourcesFilename}
|
|
|
|
''
|