Skip to content
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

[Linux] Add withWaylandGLFW override to nix package #2041

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions nix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ The wrapped packages (`prismlauncher` and `prismlauncher-qt5`) offer some build
The following parameters can be overridden:

- `msaClientID` (default: `null`, requires full rebuild!) Client ID used for Microsoft Authentication
- `gamemodeSupport` (default: `true`) Turn on/off support for [Feral GameMode](https://github.com/FeralInteractive/gamemode)
- `gamemodeSupport` (default: `true`, requires full rebuild!) Turn on/off support for [Feral GameMode](https://github.com/FeralInteractive/gamemode). Only available for Linux
- `withWaylandGLFW` (default: `false`) Turn on/off unstable, native GLFW patched to run Minecraft on Wayland. Only available on Linux, see [this](pkg/wrapper.nix#L30) comment for more.
- `textToSpeechSupport` (default: `stdenv.isLinux`) Turn on/off support for narrator. Only has an effect on Linux
- `controllerSupport` (default: `stdenv.isLinux`) Turn on/off support for controllers; useful for mods. Only has an effect on Linux
- `jdks` (default: `[ jdk17 jdk8 ]`) Java runtimes added to `PRISMLAUNCHER_JAVA_PATHS` variable
- `additionalLibs` (default: `[ ]`) Additional libraries that will be added to `LD_LIBRARY_PATH`
- `additionalLibs` (default: `[ ]`) Additional libraries that will be added to `LD_LIBRARY_PATH`. Only has an effect on Linux
35 changes: 16 additions & 19 deletions nix/distribution.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,29 @@
prismlauncher-unwrapped
prismlauncher
;

default = ourPackages.prismlauncher;
};
};

flake = {
overlays.default = final: prev: let
version = builtins.substring 0 8 self.lastModifiedDate or "dirty";

# common args for prismlauncher evaluations
unwrappedArgs = {
inherit (inputs) libnbtplusplus;
inherit ((final.darwin or prev.darwin).apple_sdk.frameworks) Cocoa;
inherit version;
};
in {
prismlauncher-qt5-unwrapped = prev.libsForQt5.callPackage ./pkg unwrappedArgs;
flake.overlays.default = final: prev: let
# common args for prismlauncher evaluations
unwrappedArgs = {
version = builtins.substring 0 7 self.rev or "dirty";
inherit (inputs) libnbtplusplus;
inherit ((final.darwin or prev.darwin).apple_sdk.frameworks) Cocoa;
};
in {
prismlauncher-qt5-unwrapped = prev.libsForQt5.callPackage ./pkg unwrappedArgs;

prismlauncher-qt5 = prev.libsForQt5.callPackage ./pkg/wrapper.nix {
prismlauncher-unwrapped = final.prismlauncher-qt5-unwrapped;
};
prismlauncher-qt5 = prev.libsForQt5.callPackage ./pkg/wrapper.nix {
prismlauncher-unwrapped = final.prismlauncher-qt5-unwrapped;
};

prismlauncher-unwrapped = prev.qt6Packages.callPackage ./pkg unwrappedArgs;
prismlauncher-unwrapped = prev.qt6Packages.callPackage ./pkg unwrappedArgs;

prismlauncher = prev.qt6Packages.callPackage ./pkg/wrapper.nix {
inherit (final) prismlauncher-unwrapped;
};
prismlauncher = prev.qt6Packages.callPackage ./pkg/wrapper.nix {
inherit (final) prismlauncher-unwrapped;
};
};
}
5 changes: 2 additions & 3 deletions nix/pkg/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
libnbtplusplus,
}:
assert lib.assertMsg (stdenv.isLinux || !gamemodeSupport) "gamemodeSupport is only available on Linux";
stdenv.mkDerivation rec {
stdenv.mkDerivation {
pname = "prismlauncher-unwrapped";
inherit version;

Expand Down Expand Up @@ -78,8 +78,7 @@ assert lib.assertMsg (stdenv.isLinux || !gamemodeSupport) "gamemodeSupport is on
their associated options with a simple interface.
'';
platforms = with platforms; linux ++ darwin;
changelog = "https://github.com/PrismLauncher/PrismLauncher/releases/tag/${version}";
Scrumplex marked this conversation as resolved.
Show resolved Hide resolved
license = licenses.gpl3Only;
maintainers = with maintainers; [minion3665 Scrumplex getchoo];
maintainers = with maintainers; [Scrumplex getchoo];
};
}
57 changes: 41 additions & 16 deletions nix/pkg/wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
symlinkJoin,
prismlauncher-unwrapped,
wrapQtAppsHook,
makeWrapper,
addOpenGLRunpath,
qtbase, # needed for wrapQtAppsHook
qtsvg,
Expand All @@ -12,34 +13,49 @@
libpulseaudio,
libGL,
glfw,
glfw-wayland-minecraft,
openal,
jdk8,
jdk17,
gamemode,
flite,
mesa-demos,
pciutils,
udev,
libusb1,
msaClientID ? null,
gamemodeSupport ? stdenv.isLinux,
textToSpeechSupport ? stdenv.isLinux,
controllerSupport ? stdenv.isLinux,
# 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,
jdks ? [jdk17 jdk8],
additionalLibs ? [],
additionalPrograms ? [],
}: let
prismlauncherFinal = prismlauncher-unwrapped.override {
}:
assert lib.assertMsg (withWaylandGLFW -> stdenv.isLinux) "withWaylandGLFW is only available on Linux"; let
unwrapped = prismlauncher-unwrapped.override {
inherit msaClientID gamemodeSupport;
};
in
symlinkJoin {
name = "prismlauncher-${prismlauncherFinal.version}";
name = "prismlauncher-${unwrapped.version}";

paths = [prismlauncherFinal];
paths = [unwrapped];

nativeBuildInputs = [
wrapQtAppsHook
];
nativeBuildInputs =
[
wrapQtAppsHook
]
# purposefully using a shell wrapper here for variable expansion
# see https://github.com/NixOS/nixpkgs/issues/172583
++ lib.optional withWaylandGLFW makeWrapper;

buildInputs =
[
Expand All @@ -48,20 +64,28 @@ in
]
++ lib.optional (lib.versionAtLeast qtbase.version "6" && stdenv.isLinux) 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 = ''
qtWrapperArgs+=(
${lib.optionalString withWaylandGLFW "--run \"$waylandPreExec\""}
)
wrapQtAppsHook
'';

qtWrapperArgs = let
runtimeLibs =
(with xorg; [
libX11
libXext
libXcursor
libXrandr
libXxf86vm
])
++ [
[
xorg.libX11
xorg.libXext
xorg.libXcursor
xorg.libXrandr
xorg.libXxf86vm

# lwjgl
libpulseaudio
libGL
Expand All @@ -81,6 +105,7 @@ in
[
xorg.xrandr
mesa-demos # need glxinfo
pciutils # need lspci
]
++ additionalPrograms;
in
Expand All @@ -91,5 +116,5 @@ in
"--prefix PATH : ${lib.makeBinPath runtimePrograms}"
];

inherit (prismlauncherFinal) meta;
inherit (unwrapped) meta;
}
Loading