graalvmXX-ce: refactor and clean up of update.nix

The update script fetches the latest versions and only
computes/downloads the sha256 if there is a new version to improve runtime.
This commit is contained in:
Thibault Gagnaux 2022-03-29 16:59:42 +02:00
parent c6203291c8
commit 50f6c0dfa7
No known key found for this signature in database
GPG key ID: 44BD0764ACAE8E25
6 changed files with 204 additions and 279 deletions

View file

@ -1,4 +1,8 @@
{ lib, callPackage, Foundation }:
/*
Add new graal versions and products here and then see update.nix on how to
generate the sources.
*/
let
mkGraal = opts: callPackage (import ./mkGraal.nix opts) {
@ -67,7 +71,7 @@ in
];
};
};
version = "22.2.0-dev-20220326_0133";
version = "22.2.0-dev-20220330_2302";
javaVersion = "17";
platforms = builtins.attrNames config;
};

View file

@ -1,12 +1,12 @@
{
"darwin-aarch64": {
"graalvm-ce|java17|22.2.0-dev-20220326_0133": {
"sha256": "72bab733783684dba422d9e04eb4fbd9103adb21db6937cf204c0c46e6ce5b7d",
"url": "https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/22.2.0-dev-20220326_0133/graalvm-ce-java17-darwin-aarch64-dev.tar.gz"
"graalvm-ce|java17|22.2.0-dev-20220330_2302": {
"sha256": "e072cdcdf1dcc7884cfe53806e997649ae829a30e1efe19b0b77a91800da79c3",
"url": "https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/22.2.0-dev-20220330_2302/graalvm-ce-java17-darwin-aarch64-dev.tar.gz"
},
"native-image-installable-svm|java17|22.2.0-dev-20220326_0133": {
"sha256": "397fd17fef67456f66820cbdae9493d16785499b91002d20fdef6e5aaf067ba7",
"url": "https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/22.2.0-dev-20220326_0133/native-image-installable-svm-java17-darwin-aarch64-dev.jar"
"native-image-installable-svm|java17|22.2.0-dev-20220330_2302": {
"sha256": "fb554d9de8252630e8bde122ca98a75d39e200390384ddb410b3c3af3898ba6a",
"url": "https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/22.2.0-dev-20220330_2302/native-image-installable-svm-java17-darwin-aarch64-dev.jar"
}
}
}

View file

@ -1,57 +0,0 @@
# Generated by ./update.sh script
{ javaVersionPlatform, ... }:
[
{
sha256 = {
"11-linux-aarch64" = "0n1cgd9rn5aw7rzbd45nlzpnqif095zwl3999vddlhpnjlyjdh0w";
"17-linux-aarch64" = "1iw27igiyzzl43yfgid1h6h7hd0xnv0rfdkp4r7r8i51sa3q7my7";
"11-linux-amd64" = "00vipkrhc7d5xxznm07pjrdjahhfg5s5vxg49xz8qxz2nwxhi1mw";
"17-linux-amd64" = "1m4v2s1b2878r6dqpcxvbqpc3s2l8l0xcbna37bbfx6rsc73wx2g";
"11-darwin-amd64" = "08v37avg439hywx2yqx0bnfpazwaja2xhyc0kj1imib6iadib042";
"17-darwin-amd64" = "16lg3qfx7j8w8cxc3abl7c19nj6jhkni99wmff153lyhyk8zjjnm";
}.${javaVersionPlatform} or null;
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/graalvm-ce-java${javaVersionPlatform}-22.0.0.2.tar.gz";
}
{
sha256 = {
"11-linux-aarch64" = "17h0yfw0lxsiblqv1nzpc6i71vh6hbwf1x6lp7kziass1a4ixm2i";
"17-linux-aarch64" = "1nvm04smzbis1jy9znac2a4yf9ajqvvmadcf5ffr521rm784g2br";
"11-linux-amd64" = "07g7fab0zj1h77a30kiswqm0hvr1m5s6crszcbyvha2v3x2a6145";
"17-linux-amd64" = "0c8qi7b63zkjrz3sz01bbmfni7pcz9nq1jv1f34lj9lcsm8gc9cc";
"11-darwin-amd64" = "0xn1frj1f4pzrd5gm6xwq31blgvz8l9249c97q3yh7p6rkk7vhh3";
"17-darwin-amd64" = "1dr80314fxcklmhi19jn3pqrsz3iivbvcxnphdzl978krm1afzq0";
}.${javaVersionPlatform} or null;
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/native-image-installable-svm-java${javaVersionPlatform}-22.0.0.2.jar";
}
{
sha256 = {
"11-linux-aarch64" = "103d91sz2dmlc5hcbi9v3d3irgb83755hz16vkknfhbbkhm5iyz0";
"17-linux-aarch64" = "0vas98knpvpajmv8bkgcf0fh7n5fy361nd47002cpppg6hrp7k9q";
"11-linux-amd64" = "0h4s1dgx2wn63pabdckl85s70s1kw97vp0c8z7izihdn2fy7w3z9";
"17-linux-amd64" = "1g98ashyvscwyn1k8mamih6qhcbxsk62x6ynd7x81ndy1karlv6q";
"11-darwin-amd64" = "1y8d6c2ri7hrvsv3aqbcp49pmxh9yppcsfnx0jcwm88wlach0p52";
"17-darwin-amd64" = "13a6rchnaczpmxga6g405z55913ayq5gwihzlvyy6shk6gwbcppw";
}.${javaVersionPlatform} or null;
url = "https://github.com/oracle/truffleruby/releases/download/vm-22.0.0.2/ruby-installable-svm-java${javaVersionPlatform}-22.0.0.2.jar";
}
{
sha256 = {
"11-linux-aarch64" = "135zkpqm8z5nzcyn5h6vdx3c09f9wb6jgzmp0llcnx8w76p71154";
"17-linux-aarch64" = "0pij3kh70lxrzmbzx8zw97f9nb0rr492l7x3n13wcr859cr8akas";
"11-linux-amd64" = "0ppvsgs216jmm5p8m34lqg2kv0awadh1dlkxb7qzcw2b6x0grzf0";
"17-linux-amd64" = "1gf0jfmqy8lp6w7bimjp0j5abzmi0ndsn4hcjvfv7123lbj52zkz";
"11-darwin-amd64" = "1mq6013crjmrpf3yvxwv9p4yn0rcdzg5z9hq9l6fpf47i8522k6p";
"17-darwin-amd64" = "15l7p48vsca4cvqxbpb9lcmafysmdsxpv6avrpxajz705j3nsvmp";
}.${javaVersionPlatform} or null;
url = "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.0.0.2/wasm-installable-svm-java${javaVersionPlatform}-22.0.0.2.jar";
}
{
sha256 = {
"11-linux-amd64" = "0m8cqqqdks34b2zv7i6qw9kzqxi1rfqsmknqa9wm0b7dqaxx209g";
"17-linux-amd64" = "12nszxp2yv35y8zkm94bnd0mnanah48y41r61ypymd19plaqmdxk";
"11-darwin-amd64" = "00g6akpv0gkw8gcxfbgcyipn6gj25yr32k1lb7iqj08bq4f2zvk7";
"17-darwin-amd64" = "1hd71qg0nmklyakl4cc29vl10fxalbyd2b5yn7x9iv6m0h1pp25g";
}.${javaVersionPlatform} or null;
url = "https://github.com/graalvm/graalpython/releases/download/vm-22.0.0.2/python-installable-svm-java${javaVersionPlatform}-22.0.0.2.jar";
}
]

View file

@ -36,14 +36,15 @@
, writeScript
, jq
, runtimeShell
, callPackage
, gawk
}:
assert useMusl -> stdenv.isLinux;
let
platform = config.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
name = if lib.hasInfix "dev" version
name =
if lib.hasInfix "dev" version
then "graalvm${javaVersion}-ce-dev"
else "graalvm${javaVersion}-ce";
sourcesFilename = "${name}-sources.json";
@ -61,20 +62,10 @@ let
(writeShellScriptBin "${stdenv.system}-musl-gcc" ''${lib.getDev musl}/bin/musl-gcc "$@"'')
]);
javaVersionPlatform = "${javaVersion}-${platform.arch}";
graalvmXXX-ce = stdenv.mkDerivation rec {
inherit version name;
srcs = map fetchurl (builtins.attrValues sources.${platform.arch});
/*let
# Some platforms doesn't have all GraalVM features
# e.g.: GraalPython on aarch64-linux
# When the platform doesn't have a feature, sha256 is null on hashes.nix
# To update hashes.nix file, run `./update.sh <graalvm-ce-version>`
maybeFetchUrl = url: if url.sha256 != null then (fetchurl url) else null;
in
(lib.remove null
(map maybeFetchUrl (hashes { inherit javaVersionPlatform; })));*/
buildInputs = lib.optionals stdenv.isLinux [
alsa-lib # libasound.so wanted by lib/libjsound.so
@ -303,7 +294,7 @@ let
passthru = {
home = graalvmXXX-ce;
updateScript = import ./update.nix {
inherit lib writeScript jq runtimeShell sourcesFilename config;
inherit lib writeScript jq runtimeShell sourcesFilename name config gawk;
graalVersion = version;
javaVersion = "java${javaVersion}";
};

View file

@ -1,16 +1,53 @@
{
javaVersion,
graalVersion,
config,
sourcesFilename,
lib,
writeScript,
jq,
runtimeShell
{ javaVersion
, graalVersion
, config
, sourcesFilename
, name
, lib
, writeScript
, jq
, runtimeShell
, gawk
}:
/*
How to use:
run `nix-shell maintainers/scripts/update.nix --argstr package graalvmXX-ce`
to update the graalvmXX-ce-sources.json file.
E.g: nix-shell maintainers/scripts/update.nix --argstr package graalvm17-ce
Basic idea:
If we know the platform, product, javaVersion and graalVersion
we can create the url. This leads to the following json structure:
{
"platform/arch1": {
"product1|javaVersion|graalVersion": { "sha256": "...", "url": "..."},
"product2|javaVersion|graalVersion": { "sha256": "...", "url": "..."},
...
},
"platform/arch2": {
...
}
}
*/
let
productJavaVersionGraalVersionSep = "|";
# isDev :: String -> Boolean
isDev = version:
lib.hasInfix "dev" version;
# getLatestVersion :: String -> String
getLatestVersion = currentVersion:
let
dev = if isDev currentVersion then "dev-" else "";
url = "https://api.github.com/repos/graalvm/graalvm-ce-${dev}builds/releases/latest";
file = builtins.fetchurl url;
json = builtins.fromJSON (builtins.readFile file);
in
lib.removePrefix "vm-" json.tag_name;
# getArchString :: String -> String
getArchString = nixArchString:
{
@ -55,7 +92,7 @@ let
# getUrl :: AttrSet -> String
getUrl = args@{ arch, graalVersion, product, javaVersion }:
if lib.hasInfix "dev" graalVersion
if isDev graalVersion
then getDevUrl args
else getReleaseUrl args;
@ -71,13 +108,14 @@ let
# getSha256 :: String -> String -> String
getSha256 = graalVersion: url:
if lib.hasInfix "dev" graalVersion
if isDev graalVersion
then computeSha256 url
else downloadSha256 url;
# cartesianZipListsWith :: (a -> b -> c) -> [a] -> [b] -> [c]
cartesianZipListsWith = f: fst: snd:
let cartesianProduct = lib.cartesianProductOfSets { a = fst; b = snd; };
let
cartesianProduct = lib.cartesianProductOfSets { a = fst; b = snd; };
fst' = builtins.catAttrs "a" cartesianProduct;
snd' = builtins.catAttrs "b" cartesianProduct;
in
@ -91,9 +129,11 @@ let
# genProductJavaVersionGraalVersionAttrSet :: String -> AttrSet
genProductJavaVersionGraalVersionAttrSet = product_javaVersion_graalVersion:
let attrNames = [ "product" "javaVersion" "graalVersion" ];
let
attrNames = [ "product" "javaVersion" "graalVersion" ];
attrValues = lib.splitString productJavaVersionGraalVersionSep product_javaVersion_graalVersion;
in zipListsToAttrs attrNames attrValues;
in
zipListsToAttrs attrNames attrValues;
# genUrlAndSha256 :: String -> String -> AttrSet
genUrlAndSha256 = arch: product_javaVersion_graalVersion:
@ -130,20 +170,48 @@ let
javaGraalVersion = javaVersion + productJavaVersionGraalVersionSep + graalVersion;
archProducts = builtins.attrValues config;
sourcesList = builtins.concatMap (genArchProductVersionList javaGraalVersion) archProducts;
sourcesAttr = builtins.foldl' (lib.recursiveUpdate) {} sourcesList;
sourcesAttr = builtins.foldl' (lib.recursiveUpdate) { } sourcesList;
in
builtins.toFile "sources.json" (builtins.toJSON sourcesAttr);
sourcesJson = genSources graalVersion javaVersion config;
# isNew :: String -> String -> Boolean
isNew = newVersion: currentVersion:
{
"-1" = false;
"0" = false;
"1" = true;
}.${builtins.toString (builtins.compareVersions newVersion currentVersion)};
newVersion = getLatestVersion graalVersion;
sourcesJson = genSources newVersion javaVersion config;
sourcesJsonPath = lib.strings.escapeShellArg ././${sourcesFilename};
defaultNixPath = lib.strings.escapeShellArg ././default.nix;
/*
updateScriptText :: String -> String -> String
Writes the json file, finds the line number of the current derivation
name, which wants to update with awk and replace the first version match
after that line.
*/
updateScriptText = newVersion: currentVersion:
if isNew newVersion currentVersion
then
''
echo "New version found. Updating ${currentVersion} -> ${newVersion}".
export PATH="${lib.makeBinPath [ jq gawk ]}:$PATH"
jq . ${sourcesJson} > ${sourcesJsonPath}
drvName=$(awk '/${name}/{ print NR; exit }' ${defaultNixPath})
awk -v drvName="$drvName" -i inplace \
'NR>drvName {sub(/${graalVersion}/, "${newVersion}")} 1' ${defaultNixPath}
''
else ''echo "No new version found. Skip updating."'';
in
writeScript "update-graal.sh" ''
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}
''
${updateScriptText newVersion graalVersion}
''

View file

@ -1,81 +0,0 @@
#!/usr/bin/env nix-shell
#!nix-shell -p coreutils curl nix jq gnused -i bash
set -eou pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
info() { echo "[INFO] $*"; }
echo_file() { echo "$@" >> hashes.nix; }
verlte() {
[ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]
}
readonly nixpkgs=../../../../..
readonly old_version="$(nix-instantiate "$nixpkgs" --eval --strict -A graalvm11-ce.version)"
if [[ -z "${1:-}" ]]; then
readonly gh_version="$(curl \
${GITHUB_TOKEN:+"-u \":$GITHUB_TOKEN\""} \
-s https://api.github.com/repos/graalvm/graalvm-ce-builds/releases/latest | \
jq --raw-output .tag_name)"
readonly new_version="${gh_version//vm-/}"
else
readonly new_version="$1"
fi
if verlte "$old_version" "$new_version"; then
info "graalvm-ce $old_version is up-to-date."
[[ -z "${FORCE:-}" ]] && exit 0
else
info "graalvm-ce $old_version is out-of-date. Updating..."
fi
readonly urls=(
"https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/graalvm-ce-java@platform@-${new_version}.tar.gz"
"https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/native-image-installable-svm-java@platform@-${new_version}.jar"
"https://github.com/oracle/truffleruby/releases/download/vm-${new_version}/ruby-installable-svm-java@platform@-${new_version}.jar"
"https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/wasm-installable-svm-java@platform@-${new_version}.jar"
"https://github.com/graalvm/graalpython/releases/download/vm-${new_version}/python-installable-svm-java@platform@-${new_version}.jar"
)
readonly platforms=(
"11-linux-aarch64"
"17-linux-aarch64"
"11-linux-amd64"
"17-linux-amd64"
"11-darwin-amd64"
"17-darwin-amd64"
)
info "Deleting old hashes.nix file..."
rm -f hashes.nix
info "Generating hashes.nix file for 'graalvm-ce' $new_version. This will take a while..."
echo_file "# Generated by $0 script"
echo_file "{ javaVersionPlatform, ... }:"
echo_file "["
for url in "${urls[@]}"; do
echo_file " {"
echo_file " sha256 = {"
for platform in "${platforms[@]}"; do
if hash="$(nix-prefetch-url "${url//@platform@/$platform}")"; then
echo_file " \"$platform\" = \"$hash\";"
fi
done
echo_file ' }.${javaVersionPlatform} or null;'
echo_file " url = \"${url//@platform@/\$\{javaVersionPlatform\}}\";"
echo_file " }"
done
echo_file "]"
info "Updating graalvm-ce version..."
# update-source-version does not work here since it expects src attribute
sed "s|$old_version|\"$new_version\"|" -i default.nix
info "Done!"