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
(ZSH?) JAVA_HOME isn't set correctly when installed to the system profile #13653
Comments
This is quite likely to be an ZSH issue. The exact same (simple) script fails if I use -i zsh, whereas it works with -i bash. |
Nope. Not an ZSH issue. I'm not sure why I got the behaviour above earlier, but now I can't reproduce it. |
Ha! I've got |
@bendlas Good question! :) I've got a temporary fix in the PR referenced above, but if you're comfortable enough with applying that locally then you can probably just use nix-shell until it's fixed properly. Whatever "properly" turns out to mean. |
Just to clarify, when you use |
I'll take that up on the mailing list. The issue is, though, that if JAVA_HOME isn't set then a lot of Java applications just won't work... And every other distribution does set the variable by default, so we should too. I'm not sure how to deal with upgrades. Possibly it'll need another symlink in /run. Anyway, mailing list... |
As a concrete test case: |
Would like to know if there is a well documented workaround for this somewhere, trying to install |
I am not convinced that nix shouldn't handle environment variables for user profiles, but maybe I could be convinced. A common situation, not unrelated to the current issue, is that apparently
|
@roman My solution for now, which may be an OK way to do this: I have the following script, #!/bin/bash
export JAVA_HOME=$(readlink -e $(type -p javac) | sed -e 's/\/bin\/javac//g')
export IDEA_JDK=/usr/lib/jvm/zulu-8-amd64
ln -sfT $JAVA_HOME $ENVSDIR/JDK A couple of extra lines there to make intellij happy - first to give it its own JVM that works well with it, and second, to provide a linked path I can easily fine for the current nix JDK, since IntelliJ doesn't like to use the environment's I have a docker container running nix/nixpkgs that has its entrypoint do some configuration to SET_DYNAMIC_ENV="source $HOME/workspace/nix-env-dynamic.sh"
grep -q -F "${SET_DYNAMIC_ENV}" $HOME/.bashrc || printf "\n$SET_DYNAMIC_ENV\n" >> $HOME/.bashrc That said, I'd like to do as little bash/perl programming as possible - I suspect you can relate ;). So, I still think it might be nice for Nix to handle this at some level. |
@bbarker this saves you the
|
@NeQuissimus I'm so inured to export JAVA_HOME=$(readlink -e $(type -p javac) | sed -e 's/\/bin\/javac//g') |
On NixOS
now sets up |
@aij A question on behalf of a friend newer to Nix :) ... what file does |
@xpe https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/programs/java.nix The easiest way I know of to find where an option is defined is to look at Finding the source of The above file has
so I looked up
So, it's still just setting the |
@aij Do your comments above apply...
|
@xpe Oops, I assumed a new user trying to understand the code... For a new user trying to configure NixOS, they'd want to put |
Basic info
To make sure that we are on the same page:
Describe your issue here
environment.systemPackages includes openjdk. However, the JAVA_HOME environment variable is not set. While this isn't a problem for scripts run through nix-shell -i bash, it breaks scripts that aren't. Possibly part of the reason for this is my use of ZSH as a default shell.
Expected result
JAVA_HOME should be set.
Actual result
It is not set.
Steps to reproduce
echo $JAVA_HOME.
Notice that it isn't set.
The text was updated successfully, but these errors were encountered: