File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ with lib;
88let
99 cfg = config . programs . java ;
1010in
11-
1211{
1312
1413 options = {
4039 type = types . package ;
4140 } ;
4241
42+ binfmt = mkEnableOption ( lib . mdDoc "binfmt to execute java jar's and classes" ) ;
43+
4344 } ;
4445
4546 } ;
4647
4748 config = mkIf cfg . enable {
4849
50+ boot . binfmt . registrations = mkIf cfg . binfmt {
51+ java-class = {
52+ recognitionType = "extension" ;
53+ magicOrExtension = "class" ;
54+ interpreter = pkgs . writeShellScript "java-class-wrapper" ''
55+ test -e ${ cfg . package } /nix-support/setup-hook && source ${ cfg . package } /nix-support/setup-hook
56+ classpath=$(dirname "$1")
57+ class=$(basename "'' ${1%%.class}")
58+ $JAVA_HOME/bin/java -classpath "$classpath" "$class" "'' ${@:2}"
59+ '' ;
60+ } ;
61+ java-jar = {
62+ recognitionType = "extension" ;
63+ magicOrExtension = "jar" ;
64+ interpreter = pkgs . writeShellScript "java-jar-wrapper" ''
65+ test -e ${ cfg . package } /nix-support/setup-hook && source ${ cfg . package } /nix-support/setup-hook
66+ $JAVA_HOME/bin/java -jar "$@"
67+ '' ;
68+ } ;
69+ } ;
70+
4971 environment . systemPackages = [ cfg . package ] ;
5072
5173 environment . shellInit = ''
You can’t perform that action at this time.
0 commit comments