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