Flake devShell: Using JRE override for SBT does not work

Dear community,

Goal and problem

I’ve tried to set up a developer environment for a project where I need Java (zulu8) and SBT. If I don’t override any settings, SBT will use its default JRE. As we use zulu8, I tried overriding the JRE setting in SBT, but this was unsuccessful.

Trials

I tried setting this:

sbt.override { jre = pkgs.zulu8; }

and the whole flake then looks like this:

{
  description = "A flake for getting started with Scala (Zulu8 JDK) & scala-cli.";

  inputs.nixpkgs.url = "github:nixos/nixpkgs";
  inputs.flake-utils.url = "github:numtide/flake-utils";

  outputs = { nixpkgs, flake-utils, ... }:
    let
      supportedSystems = [
        "aarch64-darwin"
        "aarch64-linux"
        "x86_64-linux"
        "x86_64-darwin"
      ];
    in
      flake-utils.lib.eachSystem supportedSystems (
        system: let
          pkgs = import nixpkgs { inherit system; };
          sbt8 = pkgs.sbt.override { jre = pkgs.zulu8; };
        in
    {
      devShells.default = pkgs.mkShell {
        packages = with pkgs; [  scalafmt zulu8 scala-cli ];
      };

      formatter = pkgs.default.alejandra;
    }
  );
}

If I use this, and run sbt , then I get the output

[info] welcome to sbt 1.7.1 (Azul Systems, Inc. Java 11.0.18)

which is the same as when I set the override to (note the removed ‘8’ from behind ‘zulu’):

sbt8 = pkgs.sbt.override { jre = pkgs.zulu; };

So I think something’s going wrong there between the zulu versions or with SBT not accepting older Java versions as override, but I can’t solve it. Could anyone provide some insights? :slight_smile:

Current workaround

FYI, I currently work around this issue by explicitly passing the Java directory that I want to SBT: sbt -java-home $JAVA_HOME, which shows that this does work and now successfully uses zulu8:

[info] welcome to sbt 1.7.1 (Azul Systems, Inc. Java 1.8.0_362)

Thanks in advance for any help!

Try using sbt-extras instead of sbt.
(sbt-extras.override { jdk = zulu8; }) worked for me

1 Like

Thanks Lukasz!

That worked :slight_smile:

1 Like