mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-18 15:56:50 +01:00
Merge pull request #208414 from RossComputerGuy/feat/java-binfmt
nixos/java: add binfmt option
This commit is contained in:
commit
9c1d627508
1 changed files with 23 additions and 1 deletions
|
@ -8,7 +8,6 @@ with lib;
|
|||
let
|
||||
cfg = config.programs.java;
|
||||
in
|
||||
|
||||
{
|
||||
|
||||
options = {
|
||||
|
@ -40,12 +39,35 @@ in
|
|||
type = types.package;
|
||||
};
|
||||
|
||||
binfmt = mkEnableOption (lib.mdDoc "binfmt to execute java jar's and classes");
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
|
||||
boot.binfmt.registrations = mkIf cfg.binfmt {
|
||||
java-class = {
|
||||
recognitionType = "extension";
|
||||
magicOrExtension = "class";
|
||||
interpreter = pkgs.writeShellScript "java-class-wrapper" ''
|
||||
test -e ${cfg.package}/nix-support/setup-hook && source ${cfg.package}/nix-support/setup-hook
|
||||
classpath=$(dirname "$1")
|
||||
class=$(basename "''${1%%.class}")
|
||||
$JAVA_HOME/bin/java -classpath "$classpath" "$class" "''${@:2}"
|
||||
'';
|
||||
};
|
||||
java-jar = {
|
||||
recognitionType = "extension";
|
||||
magicOrExtension = "jar";
|
||||
interpreter = pkgs.writeShellScript "java-jar-wrapper" ''
|
||||
test -e ${cfg.package}/nix-support/setup-hook && source ${cfg.package}/nix-support/setup-hook
|
||||
$JAVA_HOME/bin/java -jar "$@"
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
environment.systemPackages = [ cfg.package ];
|
||||
|
||||
environment.shellInit = ''
|
||||
|
|
Loading…
Reference in a new issue