Font errors when launching a Java Swing application

Hey all!

For my work, I currently need to build and run many Java Swing applications. The process of adding a nix configuration for each application would be immensely tedious (there are literally hundreds of them, and I only need to run each one once).

I have already found and resolved all the required dynamic link libraries that Java requires:

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

However, now when I try to launch the program it gives a different error:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Fontconfig head is null, check your fonts or fonts configuration
        at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1263)
        at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:221)
        at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:105)
        at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:696)
        ...

The internals of the program appear to run correctly (I can see its console output continuing), but the GUI does not appear.

I have attempted to create a global fonts directory, as suggested by the wiki:

  fonts = {
    enableDefaultPackages = true;
    fontDir.enable = true;
    packages = with pkgs; [
      hack-font
    ];
  };

However, this does not appear to have changed anything.

I am unsure how to resolve the issue. Any suggestions are appreciated.