Skip to content

Commit

Permalink
Update wrapper.nix
Browse files Browse the repository at this point in the history
Signed-off-by: hand7s <[email protected]>
  • Loading branch information
s0me1newithhand7s authored Jul 10, 2024
1 parent 6d9f425 commit ddef4d6
Showing 1 changed file with 118 additions and 63 deletions.
181 changes: 118 additions & 63 deletions nix/pkg/wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,150 @@
lib,
stdenv,
symlinkJoin,
prismlauncher-unwrapped,
wrapQtAppsHook,
freesmlaucnher-unwrapped,
addOpenGLRunpath,
qtbase, # needed for wrapQtAppsHook
qtsvg,
qtwayland,
xorg,
libpulseaudio,
libGL,
flite,
gamemode,
glfw,
openal,
glfw-wayland-minecraft,
glxinfo,
jdk8,
jdk17,
jdk21,
gamemode,
flite,
glxinfo,
udev,
kdePackages,
libGL,
libpulseaudio,
libusb1,
msaClientID ? null,
makeWrapper,
openal,
pciutils,
udev,
vulkan-loader,
xorg,

additionalLibs ? [ ],
additionalPrograms ? [ ],
controllerSupport ? stdenv.isLinux,
gamemodeSupport ? stdenv.isLinux,
jdks ? [
jdk21
jdk17
jdk8
],
msaClientID ? null,
textToSpeechSupport ? stdenv.isLinux,
controllerSupport ? stdenv.isLinux,
jdks ? [jdk21 jdk17 jdk8],
additionalLibs ? [],
additionalPrograms ? [],
}: let
prismlauncherFinal = prismlauncher-unwrapped.override {
inherit msaClientID gamemodeSupport;
};

# Adds `glfw-wayland-minecraft` to `LD_LIBRARY_PATH`
# when launched on wayland, allowing for the game to be run natively.
# Make sure to enable "Use system installation of GLFW" in instance settings
# for this to take effect
#
# Warning: This build of glfw may be unstable, and the launcher
# itself can take slightly longer to start
withWaylandGLFW ? false,
}:

assert lib.assertMsg (
controllerSupport -> stdenv.isLinux
) "controllerSupport only has an effect on Linux.";

assert lib.assertMsg (
textToSpeechSupport -> stdenv.isLinux
) "textToSpeechSupport only has an effect on Linux.";

assert lib.assertMsg (
withWaylandGLFW -> stdenv.isLinux
) "withWaylandGLFW is only available on Linux.";

let
freesmlaucnher' = freesmlaucnher-unwrapped.override { inherit msaClientID gamemodeSupport; };
in
symlinkJoin {
name = "prismlauncher-${prismlauncherFinal.version}";

paths = [prismlauncherFinal];
symlinkJoin {
name = "freesmlaucnher-${freesmlaucnher'.version}";

nativeBuildInputs = [
wrapQtAppsHook
];
paths = [ freesmlaucnher' ];

buildInputs =
[
qtbase
qtsvg
]
++ lib.optional (lib.versionAtLeast qtbase.version "6" && stdenv.isLinux) qtwayland;
nativeBuildInputs =
[ kdePackages.wrapQtAppsHook ]
# purposefully using a shell wrapper here for variable expansion
# see https://github.com/NixOS/nixpkgs/issues/172583
++ lib.optional withWaylandGLFW makeWrapper;

postBuild = ''
buildInputs =
[
kdePackages.qtbase
kdePackages.qtsvg
]
++ lib.optional (
lib.versionAtLeast kdePackages.qtbase.version "6" && stdenv.isLinux
) kdePackages.qtwayland;

env = {
waylandPreExec = lib.optionalString withWaylandGLFW ''
if [ -n "$WAYLAND_DISPLAY" ]; then
export LD_LIBRARY_PATH=${lib.getLib glfw-wayland-minecraft}/lib:"$LD_LIBRARY_PATH"
fi
'';
};

postBuild =
lib.optionalString withWaylandGLFW ''
qtWrapperArgs+=(--run "$waylandPreExec")
''
+ ''
wrapQtAppsHook
'';

qtWrapperArgs = let
qtWrapperArgs =
let
runtimeLibs =
(with xorg; [
libX11
libXext
libXcursor
libXrandr
libXxf86vm
])
++ [
[
# lwjgl
glfw
libpulseaudio
libGL
glfw
openal
stdenv.cc.cc.lib

# oshi
udev
vulkan-loader # VulkanMod's lwjgl

udev # oshi

xorg.libX11
xorg.libXext
xorg.libXcursor
xorg.libXrandr
xorg.libXxf86vm
]
++ lib.optional gamemodeSupport gamemode.lib
++ lib.optional textToSpeechSupport flite
++ lib.optional gamemodeSupport gamemode.lib
++ lib.optional controllerSupport libusb1
++ additionalLibs;

runtimePrograms =
[
xorg.xrandr
glxinfo
]
++ additionalPrograms;
runtimePrograms = [
glxinfo
pciutils # need lspci
xorg.xrandr # needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128
] ++ additionalPrograms;

in
["--prefix PRISMLAUNCHER_JAVA_PATHS : ${lib.makeSearchPath "bin/java" jdks}"]
++ lib.optionals stdenv.isLinux [
"--set LD_LIBRARY_PATH ${addOpenGLRunpath.driverLink}/lib:${lib.makeLibraryPath runtimeLibs}"
# xorg.xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128
"--prefix PATH : ${lib.makeBinPath runtimePrograms}"
];

inherit (prismlauncherFinal) meta;
}
[ "--prefix FREESMLAUNCHER_JAVA_PATHS : ${lib.makeSearchPath "bin/java" jdks}" ]
++ lib.optionals stdenv.isLinux [
"--set LD_LIBRARY_PATH ${addOpenGLRunpath.driverLink}/lib:${lib.makeLibraryPath runtimeLibs}"
"--prefix PATH : ${lib.makeBinPath runtimePrograms}"
];

meta = {
inherit (freesmlaucnher'.meta)
description
longDescription
homepage
changelog
license
maintainers
mainProgram
platforms
;
};
}

0 comments on commit ddef4d6

Please sign in to comment.