Installing x86 JDK 11 on ARM MacOS

Hi all,

Noob here, that just started down the nix rabbit hole a couple days now, and boy am I overwhelmed (I’m having fun though). I’ve played around with nixos, nix-darwin, and home-manager installs to see which one fits my work environment and settled with using just home-manager and nix on my m4 macbook after a week of tinkering. I’ll use nixos on my personal machines.

Now, the specific problem I have is in managing legacy applications running on java11 with dependencies around that time. This project had remained unmaintained except for light modifications and security patches. I could work on these projects on my old intel macbook but I’ve been upgraded to the m4 which meant a bunch of dependencies are now broken because these dependencies don’t even have arm builds.

That said, I would like to force an x86 build of the JDK into my setup, but keep all other packages i’m installing with my accout to pull from the aarch branch. I’m currently trying to install it using a custom flake that would pull the .dmg from azul’s site but I’m not sure if this is the appropriate approach to take. If it is, I would appreciate being sent a sample config to compare against.

Thanks for your time and guidance.

Cheers!

As a note for myself in the future and to anyone trying to do something similar, I was able to get it to work at the project level, using nix develop instead. I set pkgs to use legacyPackages.x86_64-darwin, but set the dev shell to aarch64-darwin which forces the shell to pick up the x86 jdk.

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";    
  };
  outputs = { self, nixpkgs }:
  let
    pkgs = nixpkgs.legacyPackages.x86_64-darwin;
    java = pkgs.jdk11;
    others = with pkgs; [ 
      maven
    ];
  in 
  {
    
    devShells.aarch64-darwin = {
      default = pkgs.mkShell {
        buildInputs = [ java ] ++ others;
        shellHook = ''
          ${java}/bin/java -version
        '';
      };
    };
  };
}

run nix develop afterwards, and you’ll have the expected shell setup. launch vscode or intellij from this shell and it’ll inherit the environment settings.

Now to get python27 running without nix complaining about the project being end of life.