2023-02-22 10:55:15 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, glibcLocales
|
|
|
|
# The GraalVM derivation to use
|
|
|
|
, graalvmDrv
|
|
|
|
, name ? "${args.pname}-${args.version}"
|
2021-12-06 16:07:01 +00:00
|
|
|
, executable ? args.pname
|
|
|
|
# JAR used as input for GraalVM derivation, defaults to src
|
|
|
|
, jar ? args.src
|
|
|
|
, dontUnpack ? (jar == args.src)
|
|
|
|
# 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}"
|
2023-10-19 13:55:26 +00:00
|
|
|
"-march=compatibility"
|
2021-12-06 16:07:01 +00:00
|
|
|
"--verbose"
|
|
|
|
]
|
|
|
|
# Extra arguments to be passed to the native-image
|
|
|
|
, extraNativeImageBuildArgs ? [ ]
|
|
|
|
# XMX size of GraalVM during build
|
|
|
|
, graalvmXmx ? "-J-Xmx6g"
|
2022-07-14 12:49:19 +00:00
|
|
|
# Locale to be used by GraalVM compiler
|
|
|
|
, LC_ALL ? "en_US.UTF-8"
|
2021-12-30 13:39:12 +00:00
|
|
|
, meta ? { }
|
2021-12-06 16:07:01 +00:00
|
|
|
, ...
|
|
|
|
} @ args:
|
|
|
|
|
2023-02-22 10:55:15 +00:00
|
|
|
let
|
|
|
|
extraArgs = builtins.removeAttrs args [
|
|
|
|
"lib"
|
|
|
|
"stdenv"
|
|
|
|
"glibcLocales"
|
|
|
|
"jar"
|
|
|
|
"dontUnpack"
|
|
|
|
"LC_ALL"
|
|
|
|
"meta"
|
2023-03-24 00:07:29 +00:00
|
|
|
"buildPhase"
|
|
|
|
"nativeBuildInputs"
|
|
|
|
"installPhase"
|
2023-02-22 10:55:15 +00:00
|
|
|
];
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation ({
|
|
|
|
inherit dontUnpack LC_ALL jar;
|
2021-12-06 16:07:01 +00:00
|
|
|
|
2022-04-03 18:54:34 +00:00
|
|
|
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ graalvmDrv glibcLocales ];
|
2021-12-06 16:07:01 +00:00
|
|
|
|
|
|
|
nativeImageBuildArgs = nativeImageBuildArgs ++ extraNativeImageBuildArgs ++ [ graalvmXmx ];
|
|
|
|
|
|
|
|
buildPhase = args.buildPhase or ''
|
|
|
|
runHook preBuild
|
|
|
|
|
2023-02-22 10:55:15 +00:00
|
|
|
native-image -jar "$jar" ''${nativeImageBuildArgs[@]}
|
2021-12-06 16:07:01 +00:00
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = args.installPhase or ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
install -Dm755 ${executable} -t $out/bin
|
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
2023-02-09 11:40:11 +00:00
|
|
|
disallowedReferences = [ graalvmDrv ];
|
|
|
|
|
2023-02-16 17:41:37 +00:00
|
|
|
passthru = { inherit graalvmDrv; };
|
|
|
|
|
2021-12-30 13:39:12 +00:00
|
|
|
meta = {
|
|
|
|
# default to graalvm's platforms
|
2022-04-03 18:54:34 +00:00
|
|
|
platforms = graalvmDrv.meta.platforms;
|
2021-12-30 13:39:12 +00:00
|
|
|
# default to executable name
|
|
|
|
mainProgram = executable;
|
|
|
|
} // meta;
|
2023-02-22 10:55:15 +00:00
|
|
|
} // extraArgs)
|