2024-06-30 08:12:46 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
stdenv,
|
|
|
|
glibcLocales,
|
2024-05-02 00:46:19 +00:00
|
|
|
# The GraalVM derivation to use
|
2024-06-30 08:12:46 +00:00
|
|
|
graalvmDrv,
|
|
|
|
removeReferencesTo,
|
|
|
|
executable ? args.pname,
|
2024-05-02 00:46:19 +00:00
|
|
|
# JAR used as input for GraalVM derivation, defaults to src
|
2024-06-30 08:12:46 +00:00
|
|
|
jar ? args.src,
|
|
|
|
dontUnpack ? (jar == args.src),
|
2024-05-02 00:46:19 +00:00
|
|
|
# Default native-image arguments. You probably don't want to set this,
|
|
|
|
# except in special cases. In most cases, use extraNativeBuildArgs instead
|
2024-06-30 08:12:46 +00:00
|
|
|
nativeImageBuildArgs ? [
|
2024-05-02 00:46:19 +00:00
|
|
|
(lib.optionalString stdenv.isDarwin "-H:-CheckToolchain")
|
|
|
|
(lib.optionalString (stdenv.isLinux && stdenv.isAarch64) "-H:PageSize=64K")
|
|
|
|
"-H:Name=${executable}"
|
|
|
|
"-march=compatibility"
|
|
|
|
"--verbose"
|
2024-06-30 08:12:46 +00:00
|
|
|
],
|
2024-05-02 00:46:19 +00:00
|
|
|
# Extra arguments to be passed to the native-image
|
2024-06-30 08:12:46 +00:00
|
|
|
extraNativeImageBuildArgs ? [ ],
|
2024-05-02 00:46:19 +00:00
|
|
|
# XMX size of GraalVM during build
|
2024-06-30 08:12:46 +00:00
|
|
|
graalvmXmx ? "-J-Xmx6g",
|
|
|
|
meta ? { },
|
|
|
|
LC_ALL ? "en_US.UTF-8",
|
|
|
|
...
|
|
|
|
}@args:
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
extraArgs = builtins.removeAttrs args [
|
|
|
|
"lib"
|
|
|
|
"stdenv"
|
|
|
|
"glibcLocales"
|
|
|
|
"jar"
|
|
|
|
"dontUnpack"
|
|
|
|
"LC_ALL"
|
|
|
|
"meta"
|
|
|
|
"buildPhase"
|
|
|
|
"nativeBuildInputs"
|
|
|
|
"installPhase"
|
|
|
|
"postInstall"
|
|
|
|
];
|
|
|
|
in
|
2024-06-30 08:12:46 +00:00
|
|
|
stdenv.mkDerivation (
|
|
|
|
{
|
|
|
|
inherit dontUnpack jar;
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
env = {
|
|
|
|
inherit LC_ALL;
|
|
|
|
};
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
|
|
|
|
graalvmDrv
|
|
|
|
glibcLocales
|
|
|
|
removeReferencesTo
|
|
|
|
];
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
nativeImageBuildArgs = nativeImageBuildArgs ++ extraNativeImageBuildArgs ++ [ graalvmXmx ];
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
buildPhase =
|
|
|
|
args.buildPhase or ''
|
|
|
|
runHook preBuild
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
native-image -jar "$jar" $(export -p | sed -n 's/^declare -x \([^=]\+\)=.*$/ -E\1/p' | tr -d \\n) ''${nativeImageBuildArgs[@]}
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
installPhase =
|
|
|
|
args.installPhase or ''
|
|
|
|
runHook preInstall
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
install -Dm755 ${executable} -t $out/bin
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
postInstall = ''
|
|
|
|
remove-references-to -t ${graalvmDrv} $out/bin/${executable}
|
|
|
|
${args.postInstall or ""}
|
|
|
|
'';
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
disallowedReferences = [ graalvmDrv ];
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
passthru = {
|
|
|
|
inherit graalvmDrv;
|
|
|
|
};
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:12:46 +00:00
|
|
|
meta = {
|
|
|
|
# default to graalvm's platforms
|
|
|
|
platforms = graalvmDrv.meta.platforms;
|
|
|
|
# default to executable name
|
|
|
|
mainProgram = executable;
|
|
|
|
} // meta;
|
|
|
|
}
|
|
|
|
// extraArgs
|
|
|
|
)
|