Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 89 additions & 77 deletions pkgs/build-support/build-graalvm-native-image/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,107 @@
lib,
stdenv,
glibcLocales,
# The GraalVM derivation to use
graalvmDrv,
removeReferencesTo,
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.hostPlatform.isDarwin "-H:-CheckToolchain")
(lib.optionalString (
stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64
) "-H:PageSize=64K")
"-H:Name=${executable}"
"-march=compatibility"
"--verbose"
],
# Extra arguments to be passed to the native-image
extraNativeImageBuildArgs ? [ ],
# XMX size of GraalVM during build
graalvmXmx ? "-J-Xmx6g",
meta ? { },
LC_ALL ? "en_US.UTF-8",
...
}@args:

let
extraArgs = builtins.removeAttrs args [
"lib"
"stdenv"
"glibcLocales"
"jar"
"dontUnpack"
"LC_ALL"
"meta"
"buildPhase"
"nativeBuildInputs"
"installPhase"
"postInstall"
graalvmPackages,
}:

lib.extendMkDerivation {
constructDrv = stdenv.mkDerivation;

excludeDrvArgNames = [
"executable"
"extraNativeImageBuildArgs"
"graalvmDrv"
"graalvmXmx"
"nativeImageBuildArgs"
];
in
stdenv.mkDerivation (
{
inherit dontUnpack jar;

env = { inherit LC_ALL; };
extendDrvArgs =
finalAttrs:
{
dontUnpack ? true,
strictDeps ? true,
__structuredAttrs ? true,

nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
graalvmDrv
glibcLocales
removeReferencesTo
];
# The GraalVM derivation to use
graalvmDrv ? graalvmPackages.graalvm-ce,

nativeImageBuildArgs = nativeImageBuildArgs ++ extraNativeImageBuildArgs ++ [ graalvmXmx ];
executable ? finalAttrs.meta.mainProgram,

buildPhase =
args.buildPhase or ''
runHook preBuild
# 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.hostPlatform.isDarwin "-H:-CheckToolchain")
(lib.optionalString (
stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64
) "-H:PageSize=64K")
"-H:Name=${executable}"
"-march=compatibility"
"--verbose"
],

native-image -jar "$jar" ''${nativeImageBuildArgs[@]}
# Extra arguments to be passed to the native-image
extraNativeImageBuildArgs ? [ ],

runHook postBuild
'';
# XMX size of GraalVM during build
graalvmXmx ? "-J-Xmx6g",

installPhase =
args.installPhase or ''
runHook preInstall
env ? { },
meta ? { },
passthru ? { },
...
}@args:
{
env = {
LC_ALL = "en_US.UTF-8";
} // env;

install -Dm755 ${executable} -t $out/bin
inherit dontUnpack strictDeps __structuredAttrs;

runHook postInstall
'';
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [
graalvmDrv
glibcLocales
removeReferencesTo
];

# `nativeBuildInputs` does not allow `graalvmDrv`'s propagatedBuildInput to reach here this package.
# As its `propagatedBuildInputs` is required for the build process with `native-image`, we must add it here as well.
buildInputs = [ graalvmDrv ];

nativeImageArgs = nativeImageBuildArgs ++ extraNativeImageBuildArgs ++ [ graalvmXmx ];

buildPhase =
args.buildPhase or ''
runHook preBuild

postInstall = ''
remove-references-to -t ${graalvmDrv} $out/bin/${executable}
${args.postInstall or ""}
'';
native-image -jar "$src" ''${nativeImageArgs[@]}

runHook postBuild
'';

installPhase =
args.installPhase or ''
runHook preInstall

install -Dm755 ${executable} -t $out/bin

runHook postInstall
'';

postInstall = ''
remove-references-to -t ${graalvmDrv} $out/bin/${executable}
${args.postInstall or ""}
'';

disallowedReferences = [ graalvmDrv ];
disallowedReferences = [ graalvmDrv ];

passthru = { inherit graalvmDrv; };
passthru = {
inherit graalvmDrv;
} // passthru;

meta = {
# default to graalvm's platforms
platforms = graalvmDrv.meta.platforms;
# default to executable name
mainProgram = executable;
} // meta;
}
// extraArgs
)
meta = {
# default to graalvm's platforms
inherit (graalvmDrv.meta) platforms;
} // meta;
};
}
22 changes: 8 additions & 14 deletions pkgs/by-name/ce/certificate-ripper/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
buildGraalvmNativeImage,
}:

let
buildGraalvmNativeImage (finalAttrs: {
pname = "certificate-ripper";
version = "2.4.1";

jar = maven.buildMavenPackage {
pname = "${pname}-jar";
inherit version;
src = maven.buildMavenPackage {
pname = "certificate-ripper-jar";
inherit (finalAttrs) version;

src = fetchFromGitHub {
owner = "Hakky54";
repo = "certificate-ripper";
tag = version;
tag = finalAttrs.version;
hash = "sha256-qQ5BHH+DT1sGNDGzSbclqc6+byBxyP16qvm3k9E/Yks=";
};

Expand Down Expand Up @@ -46,13 +46,6 @@ let
install -Dm644 target/crip.jar $out
'';
};
in
buildGraalvmNativeImage {
inherit pname version;

src = jar;

executable = "crip";

# Copied from pom.xml
extraNativeImageBuildArgs = [
Expand All @@ -62,10 +55,11 @@ buildGraalvmNativeImage {
];

meta = {
changelog = "https://github.com/Hakky54/certificate-ripper/releases/tag/${jar.src.tag}";
changelog = "https://github.com/Hakky54/certificate-ripper/releases/tag/${finalAttrs.version}";
description = "CLI tool to extract server certificates";
homepage = "https://github.com/Hakky54/certificate-ripper";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [ tomasajt ];
mainProgram = "crip";
};
}
})
12 changes: 5 additions & 7 deletions pkgs/by-name/cl/clj-kondo/package.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
{
lib,
buildGraalvmNativeImage,
graalvmPackages,
fetchurl,
}:

buildGraalvmNativeImage rec {
buildGraalvmNativeImage (finalAttrs: {
pname = "clj-kondo";
version = "2025.06.05";

src = fetchurl {
url = "https://github.com/clj-kondo/${pname}/releases/download/v${version}/${pname}-${version}-standalone.jar";
url = "https://github.com/clj-kondo/clj-kondo/releases/download/v${finalAttrs.version}/clj-kondo-${finalAttrs.version}-standalone.jar";
sha256 = "sha256-jmQFiL8MFIuMrHPSxW27E7yZIGf+k8J5nFVXgNGIKoM=";
};

graalvmDrv = graalvmPackages.graalvm-ce;

extraNativeImageBuildArgs = [
"-H:+ReportExceptionStackTraces"
"--no-fallback"
Expand All @@ -26,10 +23,11 @@ buildGraalvmNativeImage rec {
homepage = "https://github.com/clj-kondo/clj-kondo";
sourceProvenance = with lib.sourceTypes; [ binaryBytecode ];
license = lib.licenses.epl10;
changelog = "https://github.com/clj-kondo/clj-kondo/blob/v${version}/CHANGELOG.md";
changelog = "https://github.com/clj-kondo/clj-kondo/blob/v${finalAttrs.version}/CHANGELOG.md";
maintainers = with lib.maintainers; [
jlesquembre
bandresen
];
mainProgram = "clj-kondo";
};
}
})
13 changes: 6 additions & 7 deletions pkgs/by-name/cl/cljfmt/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
fetchurl,
nix-update-script,
testers,
cljfmt,
}:

buildGraalvmNativeImage rec {
buildGraalvmNativeImage (finalAttrs: {
pname = "cljfmt";
version = "0.13.1";

src = fetchurl {
url = "https://github.com/weavejester/cljfmt/releases/download/${version}/cljfmt-${version}-standalone.jar";
url = "https://github.com/weavejester/cljfmt/releases/download/${finalAttrs.version}/cljfmt-${finalAttrs.version}-standalone.jar";
hash = "sha256-Dj1g6hMzRhqm0pJggODVFgEkayB2Wdh3d0z6RglHbgY=";
};

Expand All @@ -28,8 +27,8 @@ buildGraalvmNativeImage rec {
passthru.updateScript = nix-update-script { };

passthru.tests.version = testers.testVersion {
inherit version;
package = cljfmt;
inherit (finalAttrs) version;
package = finalAttrs.finalPackage;
command = "cljfmt --version";
};

Expand All @@ -39,7 +38,7 @@ buildGraalvmNativeImage rec {
homepage = "https://github.com/weavejester/cljfmt";
sourceProvenance = with lib.sourceTypes; [ binaryBytecode ];
license = lib.licenses.epl10;
changelog = "https://github.com/weavejester/cljfmt/blob/${version}/CHANGELOG.md";
changelog = "https://github.com/weavejester/cljfmt/blob/${finalAttrs.version}/CHANGELOG.md";
maintainers = with lib.maintainers; [ sg-qwt ];
};
}
})
34 changes: 14 additions & 20 deletions pkgs/by-name/cl/cljstyle/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,44 @@
buildGraalvmNativeImage,
fetchMavenArtifact,
fetchurl,
graalvmPackages,
versionCheckHook,
}:

let
buildGraalvmNativeImage (finalAttrs: {
pname = "cljstyle";
version = "0.17.642";

# must be on classpath to build native image
graal-build-time = fetchMavenArtifact {
repos = [ "https://repo.clojars.org/" ];
groupId = "com.github.clj-easy";
artifactId = "graal-build-time";
version = "1.0.5";
hash = "sha256-M6/U27a5n/QGuUzGmo8KphVnNa2K+LFajP5coZiFXoY=";
};
in
buildGraalvmNativeImage {
inherit pname version;

src = fetchurl {
url = "https://github.com/greglook/${pname}/releases/download/${version}/${pname}-${version}.jar";
url = "https://github.com/greglook/cljstyle/releases/download/${finalAttrs.version}/cljstyle-${finalAttrs.version}.jar";
hash = "sha256-AkCuTZeDXbNBuwPZEMhYGF/oOGIKq5zVDwL8xwnj+mE=";
};

graalvmDrv = graalvmPackages.graalvm-ce;

extraNativeImageBuildArgs = [
"-H:+ReportExceptionStackTraces"
"--no-fallback"
"-cp ${graal-build-time.passthru.jar}"
"-cp ${finalAttrs.finalPackage.passthru.graal-build-time.passthru.jar}"
];

doInstallCheck = true;
nativeInstallCheckInputs = [ versionCheckHook ];
versionCheckProgramArg = [ "version" ];

# must be on classpath to build native image
passthru.graal-build-time = fetchMavenArtifact {
repos = [ "https://repo.clojars.org/" ];
groupId = "com.github.clj-easy";
artifactId = "graal-build-time";
version = "1.0.5";
hash = "sha256-M6/U27a5n/QGuUzGmo8KphVnNa2K+LFajP5coZiFXoY=";
};

meta = {
description = "Tool for formatting Clojure code";
homepage = "https://github.com/greglook/cljstyle";
sourceProvenance = with lib.sourceTypes; [ binaryBytecode ];
license = lib.licenses.epl10;
changelog = "https://github.com/greglook/cljstyle/blob/${version}/CHANGELOG.md";
changelog = "https://github.com/greglook/cljstyle/blob/${finalAttrs.version}/CHANGELOG.md";
maintainers = with lib.maintainers; [ psyclyx ];
mainProgram = "cljstyle";
};
}
})
Loading