Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

programs.jdks: init #988

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Conversation

Samasaur1
Copy link
Contributor

This PR allows you to install Java versions system-wide.

I've left stubs in place to allow setting the JDK to use, but I have not yet implemented that, so this only adds support for programs.jdk.installed

I've left stubs in place to allow setting the JDK in use,
but I have not yet implemented that, so this only adds support
for `programs.jdk.installed`
I thought I understood bash quoting. I do not. Here's an example:

```
[sam](~)$ for jdk in "/nix/store/fq62102p6snl4mix9w0wpzw9a91ck4l1-zulu-ca-jdk-8.0.402/*.jdk"; do echo $jdk; echo ${jdk//\//_}; done
/nix/store/fq62102p6snl4mix9w0wpzw9a91ck4l1-zulu-ca-jdk-8.0.402/zulu-8.jdk
_nix_store_fq62102p6snl4mix9w0wpzw9a91ck4l1-zulu-ca-jdk-8.0.402_*.jdk
[sam](~)$ for jdk in /nix/store/fq62102p6snl4mix9w0wpzw9a91ck4l1-zulu-ca-jdk-8.0.402/*.jdk; do echo $jdk; echo ${jdk//\//_}; done
/nix/store/fq62102p6snl4mix9w0wpzw9a91ck4l1-zulu-ca-jdk-8.0.402/zulu-8.jdk
_nix_store_fq62102p6snl4mix9w0wpzw9a91ck4l1-zulu-ca-jdk-8.0.402_zulu-8.jdk
```
@Samasaur1 Samasaur1 marked this pull request as draft November 7, 2024 18:32
@Samasaur1
Copy link
Contributor Author

I'm marking this PR as a draft because the consensus we came to in the nix-darwin Matrix room was that we'd like to wait for an overhaul of managing files outside of the Nix store. If anyone has been waiting on this PR, though, we can reconsider.

@Samasaur1
Copy link
Contributor Author

Depends on #1205, after which it should be as simple as something like

system.file = builtins.listToAttrs
  (builtins.map (jdk: 
    let
      versionElems = lib.strings.splitString "." jdk.version;
      majorVersion = builtins.elemAt versionElems 0;
    in
      lib.nameValuePair
      "Library/Java/JavaVirtualMachines/zulu-${majorVersion}.jdk"
      { source = "${jdk}/zulu-${majorVersion}.jdk"; }
  ) cfg.jdks);

@Samasaur1
Copy link
Contributor Author

As written, this PR only supports the Zulu JDKs in nixpkgs (which have macOS JDK bundles under the derivations). It should also be able to support other JDKs in nixpkgs (such as temurin-bin, which itself is a JDK bundle), so that's also on the TODO list

@Samasaur1
Copy link
Contributor Author

I'll also want to make a similar PR to home-manager because you can apparently link JDKs to ~/Library/Java/JavaVirtualMachines on a per-user basis. Since HM already has home.file, we're not waiting on that, but I'd like to handle more JDKs than just Zulu before making that PR

@Samasaur1
Copy link
Contributor Author

NixOS/nixpkgs#375212 should make it easier to find JDK bundles from any JDK in nixpkgs

@Samasaur1
Copy link
Contributor Author

With that nixpkgs PR, it becomes as simple as

home.file = builtins.listToAttrs
  (builtins.map (jdk:
    lib.nameValuePair
      "Library/Java/JavaVirtualMachines/${builtins.baseNameOf jdk.bundle}"
      { source = jdk.bundle; }
  ) cfg);

for home-manager, and the equivalent with system.file for nix-darwin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant