mirror of
https://github.com/LnL7/nix-darwin.git
synced 2024-09-11 12:49:18 +03:00
Set selected JDK in LaunchAgent
This commit is contained in:
parent
c0470488b5
commit
4402fd9f46
@ -27,13 +27,16 @@ in
|
||||
selected = lib.mkOption {
|
||||
type = with lib.types; nullOr package;
|
||||
default = null;
|
||||
example = "";
|
||||
example = lib.literalExpression
|
||||
''
|
||||
pkgs.zulu11
|
||||
'';
|
||||
description = ''
|
||||
The JDK to set as active.
|
||||
|
||||
Tools such as `java`, `javac`, etc. will use this JDK.
|
||||
|
||||
Should it also be added to the list of installed JDKs if not there?
|
||||
It will not be added to the list of installed JDKs.
|
||||
'';
|
||||
};
|
||||
};
|
||||
@ -90,24 +93,25 @@ in
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# if a JDK is selected, `launchctl setenv` it
|
||||
${lib.optionalString (cfg.selected != null) ''
|
||||
# prevent variables from propagating
|
||||
(
|
||||
# set locale to C for stable sorting
|
||||
export LC_ALL=C
|
||||
for jdk in ${cfg.selected}/*.jdk; do
|
||||
export JAVA_HOME="''${jdk}/Contents/Home"
|
||||
# ensure that this JDK is actually a macOS JDK bundle before using it
|
||||
if test -e "$JAVA_HOME"; then
|
||||
launchctl setenv JAVA_HOME "$JAVA_HOME"
|
||||
# break out of the loop so that we only set JAVA_HOME once, even if there are multiple JDKs in this derivation
|
||||
break
|
||||
fi
|
||||
done
|
||||
)
|
||||
''}
|
||||
'';
|
||||
|
||||
launchd.agents.java_home = lib.mkIf (cfg.selected != null) {
|
||||
script = ''
|
||||
export LC_ALL=C
|
||||
for jdk in ${cfg.selected}/*.jdk; do
|
||||
export JAVA_HOME="''${jdk}/Contents/Home"
|
||||
# ensure that this JDK is actually a macOS JDK bundle before using it
|
||||
if test -e "$JAVA_HOME"; then
|
||||
launchctl setenv JAVA_HOME "$JAVA_HOME"
|
||||
# break out of the loop so that we only set JAVA_HOME once, even if there are multiple JDKs in this derivation
|
||||
break
|
||||
fi
|
||||
done
|
||||
'';
|
||||
|
||||
serviceConfig = {
|
||||
RunAtLoad = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user