Java 25 Fontconfig issue

First time really doing dev work in NIxOS (only started using about a month ago) and I’ve managed well so far, even managing to get flakes working somehow, but now I’m trying to do some simple Java development using IDEA and Maven and I’m getting errors whenever I try to do anything related to fonts.

The moment I do something simple like

Font font = new Font("SansSerif", Font.PLAIN, 12);

It just spits out a Fontconfig head is null, check your fonts or configuration runtime error. I’ve tried looking wherever I could try but nothing seems to work for NixOS or maybe just my system being weird.

Among the things I’ve tried so far, they have included using the Azul Zulu OpenJDK 25 in the unstable branch instead of doing a manual package build + install myself (didn’t work), installing pkgs.fontconfig (nothing happened), exporting some sort of fontconfig or whatever to Java directly (it just confused me and only made me remember how I should never trust AI with obscure code like this), and to just enabling the fonts.fontDirs like the Wiki said and exporting it to some folder for some reason.

Nothing has worked so far, and I’m basically at a dead end now and will probably just go use some other environment entirely to develop at this point because I’ve just been so confused about everything here. Anyways, my config is basically NixOS with KDE Plasma 6 and Wayland enabled. Not sure if that’s messing with some of the way these things are handled.

Will appreciate any help if possible. I’ve been at this since 2AM in my time and it’s now 7AM…

Update: I realized that when I thought I was using the Zulu JDK 25 (in IDEA) it didn’t actually change the setup JDK in my project there. I realized that now and changed it. It actually fixed it now somehow? I’m still honestly not sure what went wrong before when I built it myself. I’ll have to look more into how other people build these new JDKs in the future instead of just trying to blindly do it all myself lol.

A bit of a confusing post but I did learn a lot (somehow), and am also curious how to actually build these packages properly. This was how I did it before (a mix of looking at documentation and just brute forcing my way through errors slowly until I figured out all the things I needed):

jdk25 = pkgs.stdenv.mkDerivation rec {
  pname = "openjdk-25";
  version = "25.0.1";

  src = pkgs.fetchzip {
    url = "https://download.java.net/java/GA/jdk25/bd75d5f9689641da8e1daabeccb5528b/36/GPL/openjdk-25_linux-x64_bin.tar.gz";
    hash = "sha256-/SbkoitGBF30XFOdbjgF9hIQWJ/6KRCErVn/9P1QTeg=";
  };

  nativeBuildInputs = [
    pkgs.autoPatchelfHook
  ];

  buildInputs = [
    pkgs.alsa-lib
    pkgs.freetype
    pkgs.libx11
    pkgs.libxext
    pkgs.libxrender
    pkgs.xorg.libXi
    pkgs.xorg.libXtst
    pkgs.zlib
    pkgs.libsigcxx
  ];

  installPhase = ''
    mkdir -p $out
    cp -r $src/* $out/
  '';
};

Hopefully I can make a more worthwhile question next time.

I had a similar issue, but want to get my Java builds running with nix-ld as my workplace does not use nix-env. For me, I needed the following in my configuration:

programs.nix-ld = {
    enable = true;
    libraries = with pkgs; [
      alsa-lib
      fontconfig
      freetype
      glibc.static
      libsigcxx
      libx11
      libxext
      libxft
      libxi
      libxrender
      libxtst
      zlib
    ];
  };

  fonts = {
    enableDefaultPackages = true;
    fontDir.enable = true;
    packages = with pkgs; [
      # Additional fonts you desire
    ];
  };

I always want the latest Java so I packaged my own OpenJDK. I had this exact issue. I declared a libfontmanager.so dependency on libfontconfig.so so autoPatchelfHook could properly do its thing.

1 Like