diff options
Diffstat (limited to 'meshmc/nix')
| -rw-r--r-- | meshmc/nix/README.md | 217 | ||||
| -rw-r--r-- | meshmc/nix/unwrapped.nix | 140 | ||||
| -rw-r--r-- | meshmc/nix/wrapper.nix | 134 |
3 files changed, 491 insertions, 0 deletions
diff --git a/meshmc/nix/README.md b/meshmc/nix/README.md new file mode 100644 index 0000000000..6ebf9ef1a5 --- /dev/null +++ b/meshmc/nix/README.md @@ -0,0 +1,217 @@ +# MeshMC Nix Packaging + +## Installing a stable release (nixpkgs) + +MeshMC is not packaged in [nixpkgs](https://github.com/NixOS/nixpkgs/). + +## Installing a development release (flake) + +We use [cachix](https://cachix.org/) to cache our development and release builds. +If you want to avoid rebuilds you may add the Cachix bucket to your substitutors, or use `--accept-flake-config` +to temporarily enable it when using `nix` commands. + +Example (NixOS): + +```nix +{ + nix.settings = { + trusted-substituters = [ "https://meshmc.cachix.org" ]; + + trusted-public-keys = [ + "meshmc.cachix.org-1:6ZNLcfqjVDKmN9/XNWGV3kcjBTL51v1v2V+cvanMkZA=" + ]; + }; +} +``` + +### Installing the package directly + +After adding `github:Project-Tick/MeshMC` to your flake inputs, you can access the flake's `packages` output. + +Example: + +```nix +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + meshmc = { + url = "github:Project-Tick/MeshMC"; + + # Optional: Override the nixpkgs input of meshmc to use the same revision as the rest of your flake + # Note that this may break the reproducibility mentioned above, and you might not be able to access the binary cache + # + # inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { nixpkgs, meshmc, ... }: + { + nixosConfigurations.foo = nixpkgs.lib.nixosSystem { + modules = [ + ./configuration.nix + + ( + { pkgs, ... }: + { + environment.systemPackages = [ meshmc.packages.${pkgs.system}.meshmc ]; + } + ) + ]; + }; + }; +} +``` + +### Using the overlay + +Alternatively, if you don't want to use our `packages` output, you can add our overlay to your nixpkgs instance. +This will ensure MeshMC is built with your system's packages. + +> [!WARNING] +> Depending on what revision of nixpkgs your system uses, this may result in binaries that differ from the above `packages` output +> If this is the case, you will not be able to use the binary cache + +Example: + +```nix +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + meshmc = { + url = "github:Project-Tick/MeshMC"; + + # Optional: Override the nixpkgs input of meshmc to use the same revision as the rest of your flake + # Note that this may break the reproducibility mentioned above, and you might not be able to access the binary cache + # + # inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { nixpkgs, meshmc, ... }: + { + nixosConfigurations.foo = nixpkgs.lib.nixosSystem { + modules = [ + ./configuration.nix + + ( + { pkgs, ... }: + { + nixpkgs.overlays = [ meshmc.overlays.default ]; + + environment.systemPackages = [ pkgs.meshmc ]; + } + ) + ]; + }; + }; +} +``` + +### Installing the package ad-hoc (`nix shell`, `nix run`, etc.) + +You can simply call the default package of this flake. + +Example: + +```shell +nix run github:Project-Tick/MeshMC + +nix shell github:Project-Tick/MeshMC + +nix profile install github:Project-Tick/MeshMC +``` + +## Installing a development release (without flakes) + +We use [Cachix](https://cachix.org/) to cache our development and release builds. +If you want to avoid rebuilds you may add the Cachix bucket to your substitutors. + +Example (NixOS): + +```nix +{ + nix.settings = { + trusted-substituters = [ "https://meshmc.cachix.org" ]; + + trusted-public-keys = [ + "meshmc.cachix.org-1:6ZNLcfqjVDKmN9/XNWGV3kcjBTL51v1v2V+cvanMkZA=" + ]; + }; +} +``` + +### Installing the package directly (`fetchTarball`) + +We use flake-compat to allow using this Flake on a system that doesn't use flakes. + +Example: + +```nix +{ pkgs, ... }: +{ + environment.systemPackages = [ + (import ( + builtins.fetchTarball "https://github.com/Project-Tick/MeshMC/archive/master.tar.gz" + )).packages.${pkgs.system}.meshmc + ]; +} +``` + +### Using the overlay (`fetchTarball`) + +Alternatively, if you don't want to use our `packages` output, you can add our overlay to your instance of nixpkgs. +This results in MeshMC using your system's libraries + +Example: + +```nix +{ pkgs, ... }: +{ + nixpkgs.overlays = [ + (import ( + builtins.fetchTarball "https://github.com/Project-Tick/MeshMC/archive/master.tar.gz" + )).overlays.default + ]; + + environment.systemPackages = [ pkgs.meshmc ]; +} +``` + +### Installing the package ad-hoc (`nix-env`) + +You can add this repository as a channel and install its packages that way. + +Example: + +```shell +nix-channel --add https://github.com/Project-Tick/MeshMC/archive/master.tar.gz meshmc + +nix-channel --update meshmc + +nix-env -iA meshmc.meshmc +``` + +## Package variants + +Both Nixpkgs and this repository offer the following packages: + +- `meshmc` - The preferred build, wrapped with everything necessary to run the launcher and Minecraft +- `meshmc-unwrapped` - A minimal build that allows for advanced customization of the launcher's runtime environment + +### Customizing wrapped packages + +The wrapped package (`meshmc`) offers some build parameters to further customize the launcher's environment. + +The following parameters can be overridden: + +- `additionalLibs` (default: `[ ]`) Additional libraries that will be added to `LD_LIBRARY_PATH` +- `additionalPrograms` (default: `[ ]`) Additional libraries that will be added to `PATH` +- `controllerSupport` (default: `isLinux`) Turn on/off support for controllers on Linux (macOS will always have this) +- `gamemodeSupport` (default: `isLinux`) Turn on/off support for [Feral GameMode](https://github.com/FeralInteractive/gamemode) on Linux +- `jdks` (default: `[ jdk21 jdk17 jdk8 ]`) Java runtimes added to `MESHMC_JAVA_PATHS` variable +- `msaClientID` (default: `null`, requires full rebuild!) Client ID used for Microsoft Authentication +- `textToSpeechSupport` (default: `isLinux`) Turn on/off support for text-to-speech on Linux (macOS will always have this) diff --git a/meshmc/nix/unwrapped.nix b/meshmc/nix/unwrapped.nix new file mode 100644 index 0000000000..aa2baf2beb --- /dev/null +++ b/meshmc/nix/unwrapped.nix @@ -0,0 +1,140 @@ +{ + lib, + stdenv, + cmake, + cmark, + extra-cmake-modules, + gamemode, + jdk17, + kdePackages, + libnbtplusplus, + ninja, + qrencode, + self, + stripJavaArchivesHook, + tomlplusplus, + zlib, + msaClientID ? null, + libarchive, +}: + +let + date = + let + # YYYYMMDD + date' = lib.substring 0 8 self.lastModifiedDate; + year = lib.substring 0 4 date'; + month = lib.substring 4 2 date'; + date = lib.substring 6 2 date'; + in + if (self ? "lastModifiedDate") then + lib.concatStringsSep "-" [ + year + month + date + ] + else + "unknown"; +in + +stdenv.mkDerivation { + pname = "meshmc-unwrapped"; + version = "7.0-unstable-${date}"; + + src = lib.fileset.toSource { + root = ../.; + fileset = lib.fileset.unions [ + ../bootstrap.sh + ../branding + ../buildconfig + ../BUILD.md + ../changelog.md + ../cmake + ../CMakeLists.txt + ../CMakePresets.json + ../CODE_OF_CONDUCT.md + ../Containerfile + ../CONTRIBUTING.md + ../COPYING.md + ../default.nix + ../doc + ../.envrc + ../flake.nix + ../.gitattributes + ../.gitmodules + ../launcher + ../lefthook.yml + ../libraries + ../LICENSES + ../.markdownlintignore + ../.markdownlint.yaml + ../nix + ../README.md + ../REUSE.toml + ../scripts + ../shell.nix + ../updater + ]; + }; + + postUnpack = '' + rm -rf source/libraries/libnbtplusplus + ln -s ${libnbtplusplus} source/libraries/libnbtplusplus + ''; + + nativeBuildInputs = [ + cmake + ninja + extra-cmake-modules + jdk17 + stripJavaArchivesHook + ]; + + buildInputs = [ + cmark + kdePackages.qtbase + kdePackages.qtnetworkauth + kdePackages.qt5compat + qrencode + libarchive + tomlplusplus + zlib + ] + ++ lib.optional stdenv.hostPlatform.isLinux gamemode; + + cmakeFlags = [ + # downstream branding + (lib.cmakeFeature "Launcher_BUILD_PLATFORM" "nixpkgs") + ] + ++ lib.optionals (msaClientID != null) [ + (lib.cmakeFeature "Launcher_MSA_CLIENT_ID" (toString msaClientID)) + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + # we wrap our binary manually + (lib.cmakeFeature "INSTALL_BUNDLE" "nodeps") + # disable built-in updater + (lib.cmakeFeature "MACOSX_SPARKLE_UPDATE_FEED_URL" "''") + (lib.cmakeFeature "CMAKE_INSTALL_PREFIX" "${placeholder "out"}/Applications/") + ]; + + doCheck = true; + + dontWrapQtApps = true; + + meta = { + description = "Free, open source launcher for Minecraft"; + longDescription = '' + Allows you to have multiple, separate instances of Minecraft (each with + their own mods, texture packs, saves, etc) and helps you manage them and + their associated options with a simple interface. + ''; + homepage = "https://projecttick.org/"; + license = lib.licenses.gpl3Plus; + maintainers = with lib.maintainers; [ + Scrumplex + getchoo + ]; + mainProgram = "meshmc"; + platforms = lib.platforms.linux ++ lib.platforms.darwin; + }; +} diff --git a/meshmc/nix/wrapper.nix b/meshmc/nix/wrapper.nix new file mode 100644 index 0000000000..289c883d85 --- /dev/null +++ b/meshmc/nix/wrapper.nix @@ -0,0 +1,134 @@ +{ + addDriverRunpath, + alsa-lib, + flite, + gamemode, + glfw3-minecraft, + jdk17, + jdk21, + jdk8, + kdePackages, + lib, + libGL, + libX11, + libXcursor, + libXext, + libXrandr, + libXxf86vm, + libjack2, + libpulseaudio, + libusb1, + mesa-demos, + openal, + pciutils, + pipewire, + meshmc-unwrapped, + stdenv, + symlinkJoin, + udev, + vulkan-loader, + xrandr, + + additionalLibs ? [ ], + additionalPrograms ? [ ], + controllerSupport ? stdenv.hostPlatform.isLinux, + gamemodeSupport ? stdenv.hostPlatform.isLinux, + jdks ? [ + jdk21 + jdk17 + jdk8 + ], + msaClientID ? null, + textToSpeechSupport ? stdenv.hostPlatform.isLinux, +}: + +assert lib.assertMsg ( + controllerSupport -> stdenv.hostPlatform.isLinux +) "controllerSupport only has an effect on Linux."; + +assert lib.assertMsg ( + textToSpeechSupport -> stdenv.hostPlatform.isLinux +) "textToSpeechSupport only has an effect on Linux."; + +let + meshmc' = meshmc-unwrapped.override { inherit msaClientID; }; +in + +symlinkJoin { + name = "meshmc-${meshmc'.version}"; + + paths = [ meshmc' ]; + + nativeBuildInputs = [ kdePackages.wrapQtAppsHook ]; + + buildInputs = [ + kdePackages.qtbase + kdePackages.qtimageformats + kdePackages.qtsvg + ] + ++ lib.optional ( + lib.versionAtLeast kdePackages.qtbase.version "6" && stdenv.hostPlatform.isLinux + ) kdePackages.qtwayland; + + postBuild = '' + wrapQtAppsHook + ''; + + qtWrapperArgs = + let + runtimeLibs = [ + (lib.getLib stdenv.cc.cc) + ## native versions + glfw3-minecraft + openal + + ## openal + alsa-lib + libjack2 + libpulseaudio + pipewire + + ## glfw + libGL + libX11 + libXcursor + libXext + libXrandr + libXxf86vm + + udev # oshi + + vulkan-loader # VulkanMod's lwjgl + ] + ++ lib.optional textToSpeechSupport flite + ++ lib.optional gamemodeSupport gamemode.lib + ++ lib.optional controllerSupport libusb1 + ++ additionalLibs; + + runtimePrograms = [ + mesa-demos + pciutils # need lspci + xrandr # needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128 + ] + ++ additionalPrograms; + + in + [ "--prefix MESHMC_JAVA_PATHS : ${lib.makeSearchPath "bin/java" jdks}" ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ + "--set LD_LIBRARY_PATH ${addDriverRunpath.driverLink}/lib:${lib.makeLibraryPath runtimeLibs}" + "--prefix PATH : ${lib.makeBinPath runtimePrograms}" + ]; + + meta = { + inherit (meshmc'.meta) + description + longDescription + homepage + changelog + license + maintainers + mainProgram + platforms + ; + }; +} |
