How to compile and package an app with GraalVM

hi, now that PR 61475 (an update for graalvm) got merged, I’d like to add a package to nixpkgs that compiles a jvm app with it.
But I’m not sure how to start with it, is there any example or previous PR of compiling a program with graal? It’d be nice to see what other people did

something like

stdenv.mkDerivation {
  name = "program";
  buildInputs = [ graalvm8 artifacts ]; # graalvm8 (as well as any other jvm) has a hook which form $CLASSPATH containing share/java/*.jar of all dependendencies
  buildPhase = ''
    native-image --no-server -cp $CLASSPATH com.example.Main
  '';
  installPhase = ''
    cp com.example.main $out/bin/program.exe
  '';
}
1 Like

Thanks @volth, it was really useful, I just created a PR for a new package compiled with GraalVM :slight_smile:

https://github.com/NixOS/nixpkgs/pull/66344

@volth thank you for all your work to make graalvm available in nix, great job. And also thank you for your help and feedback with my PR, now is merged :slight_smile:

We can try to compile to native code other small utils written in JVM languages (coursier, scalafmt, …) to improve startup time and reduce closure size

1 Like