gradle deps via nix

This commit is contained in:
Gregor Lohaus
2026-05-27 15:57:53 +02:00
parent 38486df66b
commit ea13af63a6
2 changed files with 44 additions and 57 deletions

View File

@@ -8,6 +8,8 @@ JavaFX canvas terminal prototype using `jlibghostty` for terminal emulation, Nix
nix build nix build
``` ```
The package build compiles with Nix-provided OpenJFX 25, `jlibghostty`, JToml, and GraalVM Native Image directly so it does not depend on Gradle plugin resolution inside the Nix sandbox.
For development: For development:
```sh ```sh
@@ -16,7 +18,7 @@ gradle -PjlibghosttyMavenRepo="$JLIBGHOSTTY_MAVEN_REPO" run
gradle -PjlibghosttyMavenRepo="$JLIBGHOSTTY_MAVEN_REPO" nativeCompile gradle -PjlibghosttyMavenRepo="$JLIBGHOSTTY_MAVEN_REPO" nativeCompile
``` ```
The current flake follows the normal Gradle dependency-resolution shape. For a fully pure Nix build, vendor the Gradle dependency graph with `gradle2nix` or a checked-in Maven repository. The Gradle project is kept for interactive development and IDE import.
## Config ## Config

View File

@@ -4,9 +4,14 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
jlibghostty.url = "git+https://gitea.gregorlohaus.com/gregor/jlibghostty.git"; jlibghostty.url = "git+https://gitea.gregorlohaus.com/gregor/jlibghostty.git";
jtoml-all = {
url = "https://repo.maven.apache.org/maven2/io/github/wasabithumb/jtoml-all/1.5.2/jtoml-all-1.5.2.jar";
flake = false;
};
}; };
outputs = { self, nixpkgs, jlibghostty }: outputs = { self, nixpkgs, jlibghostty, jtoml-all }:
let let
system = "x86_64-linux"; system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
@@ -14,48 +19,7 @@
jlib = jlibghostty.packages.${system}.jlibghostty; jlib = jlibghostty.packages.${system}.jlibghostty;
graalvm = pkgs.graalvmPackages.graalvm-ce; graalvm = pkgs.graalvmPackages.graalvm-ce;
gradle = if pkgs ? gradle_9 then pkgs.gradle_9 else pkgs.gradle; gradle = if pkgs ? gradle_9 then pkgs.gradle_9 else pkgs.gradle;
gradleDeps = pkgs.stdenvNoCC.mkDerivation { openjfx = pkgs.javaPackages.openjfx25;
pname = "jprototerm-gradle-deps";
version = "0.1.0";
src = ./.;
nativeBuildInputs = [
graalvm
gradle
];
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = pkgs.lib.fakeHash;
buildPhase = ''
runHook preBuild
export HOME=$TMPDIR/home
export GRADLE_USER_HOME=$out
mkdir -p "$HOME" "$GRADLE_USER_HOME"
gradle \
--no-daemon \
--stacktrace \
-PjlibghosttyMavenRepo=${jlib}/maven \
help
gradle \
--no-daemon \
--stacktrace \
-PjlibghosttyMavenRepo=${jlib}/maven \
dependencies \
--configuration runtimeClasspath
runHook postBuild
'';
installPhase = ''
runHook preInstall
runHook postInstall
'';
};
in { in {
packages.${system}.default = pkgs.stdenvNoCC.mkDerivation { packages.${system}.default = pkgs.stdenvNoCC.mkDerivation {
pname = "jprototerm"; pname = "jprototerm";
@@ -64,25 +28,45 @@
nativeBuildInputs = [ nativeBuildInputs = [
graalvm graalvm
gradle
pkgs.makeWrapper pkgs.makeWrapper
]; ];
buildPhase = '' buildPhase = ''
runHook preBuild runHook preBuild
export HOME=$TMPDIR/home mkdir -p build/classes build/native-image
export GRADLE_USER_HOME=$TMPDIR/gradle
mkdir -p "$HOME" "$GRADLE_USER_HOME"
cp -R ${gradleDeps}/. "$GRADLE_USER_HOME"
chmod -R u+w "$GRADLE_USER_HOME"
gradle \ find src/main/java -name '*.java' | sort > build/sources.txt
--no-daemon \ jlib_classpath="$(
--offline \ find ${jlib}/maven -type f -name '*.jar' \
--stacktrace \ ! -name '*-sources.jar' \
-PjlibghosttyMavenRepo=${jlib}/maven \ ! -name '*-javadoc.jar' \
nativeCompile | sort \
| paste -sd: -
)"
app_classpath="build/classes:${jtoml-all}:$jlib_classpath"
javac \
--release 25 \
--module-path ${openjfx}/lib \
--add-modules javafx.controls,javafx.graphics \
-cp "${jtoml-all}:$jlib_classpath" \
-d build/classes \
@build/sources.txt
if [ -d src/main/resources ]; then
cp -R src/main/resources/. build/classes/
fi
native-image \
--no-fallback \
--enable-url-protocols=file \
--module-path ${openjfx}/lib \
--add-modules javafx.controls,javafx.graphics \
-cp "$app_classpath" \
-H:Name=jprototerm \
-H:Class=com.gregor.jprototerm.Main \
-H:Path=build/native-image
runHook postBuild runHook postBuild
''; '';
@@ -91,10 +75,11 @@
runHook preInstall runHook preInstall
mkdir -p $out/bin mkdir -p $out/bin
cp build/gluonfx/*/*/jprototerm $out/bin/jprototerm cp build/native-image/jprototerm $out/bin/jprototerm
wrapProgram $out/bin/jprototerm \ wrapProgram $out/bin/jprototerm \
--set GDK_BACKEND x11 \ --set GDK_BACKEND x11 \
--prefix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath [ openjfx jlib ]} \
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.util-linux pkgs.bash ]} --prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.util-linux pkgs.bash ]}
runHook postInstall runHook postInstall