2022-03-31 23:35:44 +02:00
|
|
|
{ lib, stdenv, graalvm, glibcLocales }:
|
2021-11-23 15:56:37 +01:00
|
|
|
|
|
|
|
{ name ? "${args.pname}-${args.version}"
|
|
|
|
# Final executable name
|
2021-11-23 16:35:55 +01:00
|
|
|
, executable ? args.pname
|
2021-11-23 15:56:37 +01:00
|
|
|
# JAR used as input for GraalVM derivation, defaults to src
|
|
|
|
, jar ? args.src
|
|
|
|
, dontUnpack ? (jar == args.src)
|
2021-11-23 21:36:57 +01:00
|
|
|
# Default native-image arguments. You probably don't want to set this,
|
|
|
|
# except in special cases. In most cases, use extraNativeBuildArgs instead
|
|
|
|
, nativeImageBuildArgs ? [
|
|
|
|
"-jar" jar
|
|
|
|
"-H:CLibraryPath=${lib.getLib graalvm}/lib"
|
|
|
|
(lib.optionalString stdenv.isDarwin "-H:-CheckToolchain")
|
|
|
|
"-H:Name=${executable}"
|
|
|
|
"--verbose"
|
|
|
|
]
|
2021-11-23 15:56:37 +01:00
|
|
|
# Extra arguments to be passed to the native-image
|
|
|
|
, extraNativeImageBuildArgs ? [ ]
|
|
|
|
# XMX size of GraalVM during build
|
|
|
|
, graalvmXmx ? "-J-Xmx6g"
|
2022-03-31 23:35:44 +02:00
|
|
|
# The GraalVM derivation to use
|
|
|
|
, graalvmDrv ? graalvm
|
2021-12-27 23:49:52 +01:00
|
|
|
, meta ? { }
|
2021-11-23 15:56:37 +01:00
|
|
|
, ...
|
|
|
|
} @ args:
|
|
|
|
|
|
|
|
stdenv.mkDerivation (args // {
|
|
|
|
inherit dontUnpack;
|
|
|
|
|
2022-03-31 23:35:44 +02:00
|
|
|
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ graalvmDrv glibcLocales ];
|
2021-11-23 15:56:37 +01:00
|
|
|
|
2021-11-23 21:36:57 +01:00
|
|
|
nativeImageBuildArgs = nativeImageBuildArgs ++ extraNativeImageBuildArgs ++ [ graalvmXmx ];
|
2021-11-23 15:56:37 +01:00
|
|
|
|
|
|
|
buildPhase = args.buildPhase or ''
|
2022-01-04 09:56:34 +01:00
|
|
|
export LC_ALL="en_US.UTF-8"
|
|
|
|
|
2021-11-23 15:56:37 +01:00
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
native-image ''${nativeImageBuildArgs[@]}
|
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = args.installPhase or ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
install -Dm755 ${executable} -t $out/bin
|
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
2021-12-27 23:49:52 +01:00
|
|
|
meta = {
|
|
|
|
# default to graalvm's platforms
|
2022-03-31 23:35:44 +02:00
|
|
|
platforms = graalvmDrv.meta.platforms;
|
2021-12-27 23:49:52 +01:00
|
|
|
# default to executable name
|
|
|
|
mainProgram = executable;
|
2022-04-16 00:20:52 +02:00
|
|
|
# need to have native-image-installable-svm available
|
|
|
|
broken = !(builtins.elem "native-image-installable-svm" graalvmDrv.products);
|
2021-12-27 23:49:52 +01:00
|
|
|
} // meta;
|
2021-11-23 15:56:37 +01:00
|
|
|
})
|