JavaFX on Flox given no overlays

What is the best way to go about providing a Java version with JavaFX in a flox environment?

In nix, I would use an overlay to override the enableJavaFX flag. In Flox, I don’t believe this is an option. I know Zulu usually provides JavaFX-in-by-default builds, but the ones that show up in flox search don’t appear to contain JavaFX. I looked at ways to use a flake to provide this, but don’t see an existing flake and before I make one I wanted to check in and see if there was a better way to do this.

If anyone is interested (since I remember this was hard to find on the internet when I first started nix) this is what a working flake that does this looks like:

{
  description = "Java with JavaFX";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";

  outputs = { self, nixpkgs }: {
    packages.x86_64-linux.java-with-javafx = with nixpkgs.legacyPackages.x86_64-linux; let
      jdk = zulu17;
    in
      jdk.override {
        enableJavaFX = true;
      };
    defaultPackage.x86_64-linux = self.packages.x86_64-linux.java-with-javafx;
    devShell.x86_64-linux = with nixpkgs.legacyPackages.x86_64-linux; mkShell {
      buildInputs = [ self.packages.x86_64-linux.java-with-javafx ];
    };
  };
}

You can test this by running nix develop in the directory containing the flake, and reference it in your flox config like so:

[install]
java = { flake = "/home/username/git/javafx-nix" }

I will resolve this issue, since the above flake works well for me, and I believe I’ve answered my own question with some tinkering. Please do let me know, though, if there is a better way to solve this in the flox ecosystem.

tl;dr, if you need an overlay for a nix package inside of flox, encapsulate that overlay in a very simple flake, and then publish that flake and reference it in your flox config.

1 Like

Looks pretty good, thanks for the example. I tend to use builtins.mapAttrs to apply the override to all the systems in Nixpkgs.

1 Like