{ description = "Java FFM bindings for libghostty-vt"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; ghostty = { url = "github:ghostty-org/ghostty"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { self, nixpkgs, ghostty }: let systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; forAllSystems = nixpkgs.lib.genAttrs systems; in { packages = forAllSystems (system: let pkgs = import nixpkgs { inherit system; }; jdk = if pkgs ? jdk25_headless then pkgs.jdk25_headless else if pkgs ? jdk25 then pkgs.jdk25 else if pkgs ? jdk24_headless then pkgs.jdk24_headless else if pkgs ? jdk24 then pkgs.jdk24 else pkgs.jdk; graalvm = pkgs.graalvmPackages.graalvm-ce; version = "0.1.0-SNAPSHOT"; groupPath = "dev/jlibghostty"; artifactId = "jlibghostty"; ghosttyVt = ghostty.packages.${system}.libghostty-vt; platformName = if system == "x86_64-linux" then "linux-x86_64" else if system == "aarch64-linux" then "linux-aarch64" else if system == "x86_64-darwin" then "macos-x86_64" else if system == "aarch64-darwin" then "macos-aarch64" else throw "unsupported system: ${system}"; bundledLibraryName = if pkgs.stdenv.hostPlatform.isDarwin then "libghostty-vt.dylib" else "libghostty-vt.so"; sharedLibraryPattern = if pkgs.stdenv.hostPlatform.isDarwin then "libghostty-vt*.dylib" else "libghostty-vt.so*"; package = pkgs.stdenvNoCC.mkDerivation { pname = artifactId; inherit version; src = ./.; nativeBuildInputs = [ jdk ]; dontConfigure = true; buildPhase = '' runHook preBuild mkdir -p build/classes build/test-classes build/resources/${groupPath}/native/${platformName} if [ -d src/main/resources ]; then cp -R src/main/resources/. build/resources/ fi ghostty_lib="$(find ${ghosttyVt} -type f -name '${sharedLibraryPattern}' -print -quit)" if [ -z "$ghostty_lib" ]; then echo "Could not find ${sharedLibraryPattern} in ${ghosttyVt}" >&2 find ${ghosttyVt} -maxdepth 4 -type f >&2 exit 1 fi bundled_lib="build/resources/${groupPath}/native/${platformName}/${bundledLibraryName}" cp "$ghostty_lib" "$bundled_lib" find src/main/java -name '*.java' | sort > build/sources.txt javac --release 25 --module-path ${graalvm}/jmods -d build/classes @build/sources.txt jar --create \ --file build/${artifactId}-${version}.jar \ -C build/classes . \ -C build/resources . jar --create \ --file build/${artifactId}-${version}-sources.jar \ -C src/main/java . find src/test/java -name '*.java' | sort > build/test-sources.txt if [ -s build/test-sources.txt ]; then javac --release 25 -cp build/classes -d build/test-classes @build/test-sources.txt java \ --enable-native-access=ALL-UNNAMED \ -Djlibghostty.library.path="$bundled_lib" \ -cp build/classes:build/test-classes \ dev.jlibghostty.GhosttySmokeTest fi runHook postBuild ''; installPhase = '' runHook preInstall mkdir -p "$out/share/java" "$out/maven/${groupPath}/${artifactId}/${version}" cp build/${artifactId}-${version}.jar "$out/share/java/" cp build/${artifactId}-${version}.jar "$out/maven/${groupPath}/${artifactId}/${version}/" cp build/${artifactId}-${version}-sources.jar "$out/maven/${groupPath}/${artifactId}/${version}/" cat > "$out/maven/${groupPath}/${artifactId}/${version}/${artifactId}-${version}.pom" <<'POM' 4.0.0 dev.jlibghostty jlibghostty 0.1.0-SNAPSHOT jlibghostty Java FFM bindings for libghostty-vt POM runHook postInstall ''; meta = { description = "Java FFM bindings for libghostty-vt"; platforms = systems; }; }; in { default = package; jlibghostty = package; mavenRepository = package; }); devShells = forAllSystems (system: let pkgs = import nixpkgs { inherit system; }; jdk = if pkgs ? jdk25_headless then pkgs.jdk25_headless else if pkgs ? jdk25 then pkgs.jdk25 else if pkgs ? jdk24_headless then pkgs.jdk24_headless else if pkgs ? jdk24 then pkgs.jdk24 else pkgs.jdk; graalvm = pkgs.graalvmPackages.graalvm-ce; ghosttyVt = ghostty.packages.${system}.libghostty-vt; in { default = pkgs.mkShell { packages = [ jdk pkgs.gradle graalvm ] ++ pkgs.lib.optional (pkgs ? jextract) pkgs.jextract; GRAALVM_HOME = "${graalvm}"; JLIBGHOSTTY_LIBRARY = if pkgs.stdenv.hostPlatform.isDarwin then "${ghosttyVt}/lib/libghostty-vt.dylib" else "${ghosttyVt}/lib/libghostty-vt.so"; }; }); }; }