diff --git a/.github/workflows/cachix.yml b/.github/workflows/cachix.yml index a83566a89..f723e28c9 100644 --- a/.github/workflows/cachix.yml +++ b/.github/workflows/cachix.yml @@ -32,7 +32,7 @@ jobs: with: name: freesmlauncher authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" - - run: nix-build | cachix push freesmlauncher + - run: nix build | cachix push freesmlauncher - run: | nix develop echo "OK" diff --git a/default.nix b/default.nix deleted file mode 100644 index c1b8a65d7..000000000 --- a/default.nix +++ /dev/null @@ -1,10 +0,0 @@ -(import ( - let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - in - fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - } -) {src = ./.;}) -.defaultNix diff --git a/flake.lock b/flake.lock index 04e03810f..1ee1006ff 100644 --- a/flake.lock +++ b/flake.lock @@ -1,21 +1,5 @@ { "nodes": { - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1767039857, - "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, "libnbtplusplus": { "flake": false, "locked": { @@ -65,7 +49,6 @@ }, "root": { "inputs": { - "flake-compat": "flake-compat", "libnbtplusplus": "libnbtplusplus", "nix-filter": "nix-filter", "nixpkgs": "nixpkgs" diff --git a/flake.nix b/flake.nix index e284af0f7..9513bdb4d 100644 --- a/flake.nix +++ b/flake.nix @@ -15,104 +15,82 @@ }; inputs = { - nixpkgs = { - url = "github:NixOS/nixpkgs/nixos-unstable"; - }; - - nix-filter = { - url = "github:numtide/nix-filter"; - }; - + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + nix-filter.url = "github:numtide/nix-filter"; libnbtplusplus = { url = "github:FreesmTeam/libnbtplusplus"; flake = false; }; - - flake-compat = { - url = "github:edolstra/flake-compat"; - flake = false; - }; }; outputs = { self, nixpkgs, - libnbtplusplus, nix-filter, + libnbtplusplus, ... }: let - inherit (nixpkgs) lib; - systems = lib.systems.flakeExposed; - forAllSystems = lib.genAttrs systems; - nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system}); + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + forEachSystem = nixpkgs.lib.genAttrs systems; in { - formatter = forAllSystems (system: nixpkgsFor.${system}.alejandra); - devShells = forAllSystems ( - system: let - pkgs = nixpkgsFor.${system}; - in { - default = pkgs.mkShell { - inputsFrom = [ - self.packages.${system}.freesmlauncher-unwrapped - ]; - buildInputs = [ - pkgs.ccache - pkgs.ninja - ]; - shellHook = '' - # https://discourse.nixos.org/t/qt-development-environment-on-a-flake-system/23707/5 - setQtEnvironment=$(mktemp) - random=$(openssl rand -base64 20 | sed "s/[^a-zA-Z0-9]//g") - makeWrapper "$(type -p sh)" "$setQtEnvironment" "''${qtWrapperArgs[@]}" --argv0 "$random" - sed "/$random/d" -i "$setQtEnvironment" - source "$setQtEnvironment" - ''; - }; - } - ); + overlays.default = final: prev: { + freesmlauncher-unwrapped = final.callPackage ./nix/unwrapped.nix { + inherit nix-filter libnbtplusplus self; + }; + + freesmlauncher = final.callPackage ./nix/wrapper.nix; + }; - overlays = { - default = final: prev: { - freesmlauncher-unwrapped = prev.callPackage ./nix/unwrapped.nix { - inherit - libnbtplusplus - nix-filter - self - ; - }; + packages = forEachSystem (system: let + pkgs = import nixpkgs {inherit system;}; - freesmlauncher = final.callPackage ./nix/wrapper.nix {}; + freesmlauncher-unwrapped = pkgs.callPackage ./nix/unwrapped.nix { + inherit nix-filter libnbtplusplus self; + }; + + freesmlauncher = pkgs.callPackage ./nix/wrapper.nix { + inherit freesmlauncher-unwrapped; }; - }; - packages = forAllSystems ( - system: let - pkgs = nixpkgsFor.${system}; + freesmlauncher-unwrapped-debug = freesmlauncher-unwrapped.overrideAttrs { + cmakeBuildType = "Debug"; + dontStrip = true; + }; - freesmPackages = lib.makeScope pkgs.newScope (final: self.overlays.default final pkgs); + freesmlauncher-debug = pkgs.callPackage ./nix/wrapper.nix { + freesmlauncher-unwrapped = freesmlauncher-unwrapped-debug; + }; + in { + inherit freesmlauncher freesmlauncher-unwrapped freesmlauncher-debug freesmlauncher-unwrapped-debug; - packages = { - inherit (freesmPackages) freesmlauncher-unwrapped freesmlauncher; - default = freesmPackages.freesmlauncher; - }; - in - lib.filterAttrs (_: lib.meta.availableOn pkgs.stdenv.hostPlatform) packages - ); + default = freesmlauncher; + }); - legacyPackages = forAllSystems ( - system: let - freesmPackages = self.packages.${system}; - legacyPackages = self.legacyPackages.${system}; - in { - freesmlauncher-debug = freesmPackages.freesmlauncher.override { - freesmlauncher-unwrapped = legacyPackages.freesmlauncher-unwrapped-debug; - }; + devShells = forEachSystem (system: let + pkgs = import nixpkgs { + inherit system; + overlays = [self.overlays.default]; + }; + in { + default = pkgs.mkShell { + inputsFrom = [pkgs.freesmlauncher-unwrapped]; + + packages = with pkgs; [ + ccache + ninja + ]; + }; + }); - freesmlauncher-unwrapped-debug = freesmPackages.freesmlauncher-unwrapped.overrideAttrs { - cmakeBuildType = "Debug"; - dontStrip = true; - }; - } + formatter = forEachSystem ( + system: + (import nixpkgs {inherit system;}).alejandra ); }; } diff --git a/nix/README.md b/nix/README.md index c5bdc8a3b..0fb50ed1a 100644 --- a/nix/README.md +++ b/nix/README.md @@ -1,37 +1,84 @@ +# NixOS + > [!IMPORTANT] -> We are using **Garnix CI** for binary caching. -> To add the binary cache manually, proceed to read [this](https://garnix.io/docs/ci/caching). +> We use **Garnix CI** for binary caching. +> To configure the cache manually, follow the official guide: +> +> - [Garnix binary cache guide](https://garnix.io/docs/ci/caching) > -> We also use **[Cachix](https://app.cachix.org/cache/freesmlauncher#pull)** as a second cache for binary caching. -> For more information, check out [this guide](https://docs.cachix.org/getting-started#using-binaries-with-nix). +> We also provide a secondary cache through [**Cachix**](https://app.cachix.org/cache/freesmlauncher#pull). +> Additional information is available in the official +> [Cachix getting started guide](https://docs.cachix.org/getting-started#using-binaries-with-nix). + +
+ +# Running and installing on NixOS ---- +This guide explains how to run and install **FreesmLauncher** on NixOS. + +
+ +## Running without installation + +```fish +nix run github:FreesmTeam/FreesmLauncher#freesmlauncher +``` -###
Using on NixOS / Nixpkgs
+## Installation -Currently, **Freesm** isn't in `nixpkgs` (yet?). To use it, you'll need to add it in your `flake.nix`: +Add the flake input to your `flake.nix`: ```nix { - inputs = { - freesmlauncher = { - url = "github:FreesmTeam/FreesmLauncher"; - inputs = { - nixpkgs = { - follows = "nixpkgs"; - }; - }; - }; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + freesmlauncher = { + url = "github:FreesmTeam/FreesmLauncher"; + inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { - self, - nixpkgs, - home-manager, - freesmlauncher, - ... - } @ inputs : - ... # rest of flake. + }; + + outputs = { self, nixpkgs, freesmlauncher, ... }: { + # your outputs + }; +} +``` + +### NixOS configuration + +```nix +{ pkgs, system, freesmlauncher, ... }: + +{ + environment.systemPackages = [ + freesmlauncher.packages.${system}.freesmlauncher + ]; } ``` -After that, you can add freesmlauncher to environment.systemPackages, users.users.<>.packages, or home.packages. +### Home Manager configuration + +```nix +{ pkgs, system, freesmlauncher, ... }: + +{ + home.packages = [ + freesmlauncher.packages.${system}.freesmlauncher + ]; +} +``` + +## Updating + +To update the flake input: + +```fish +nix flake update freesmlauncher +``` + +Or update all inputs: + +```fish +nix flake update +``` diff --git a/nix/unwrapped.nix b/nix/unwrapped.nix index 8251cff6c..b8d822bd1 100644 --- a/nix/unwrapped.nix +++ b/nix/unwrapped.nix @@ -1,115 +1,109 @@ { lib, self, - zlib, - stdenv ? clangStdenv, - darwin, - kdePackages, - tomlplusplus, - ghc_filesystem, - stripJavaArchivesHook, + libnbtplusplus, + stdenv, cmake, ninja, jdk17, + stripJavaArchivesHook, + kdePackages, cmark, qrencode, - clangStdenv, - gamemode, - nix-filter, - libnbtplusplus, + zlib, + tomlplusplus, + ghc_filesystem, libarchive, + darwin, + gamemode, extra-cmake-modules, + nix-filter, msaClientID ? null, gamemodeSupport ? stdenv.hostPlatform.isLinux, -}: -assert lib.assertMsg ( - gamemodeSupport -> stdenv.hostPlatform.isLinux -) "gamemodeSupport is only available on Linux."; - stdenv.mkDerivation { - pname = "freesmlauncher-unwrapped"; - version = self.shortRev or self.dirtyShortRev or "_git"; +}: let + isDarwin = stdenv.hostPlatform.isDarwin; +in + assert lib.assertMsg (gamemodeSupport -> stdenv.hostPlatform.isLinux) + "gamemodeSupport only on linux"; + stdenv.mkDerivation { + pname = "freesmlauncher-unwrapped"; + version = self.shortRev or self.dirtyShortRev or "_git"; + src = nix-filter.lib { + root = self; + include = [ + "buildconfig" + "cmake" + "launcher" + "libraries" + "program_info" + "tests" + ../docs/COPYING.md + ../CMakeLists.txt + ]; - src = nix-filter.lib { - root = self; - include = [ - "buildconfig" - "cmake" - "launcher" - "libraries" - "program_info" - "tests" - ../docs/COPYING.md - ../CMakeLists.txt - ]; - - # Some fetchers leave submodules directories empty instead of omitting them, causing Garnix CI cache misses. - exclude = [ - "libraries/libnbtplusplus" - ]; - }; + # Some fetchers leave submodules directories empty instead of omitting them, causing Garnix CI cache misses. + exclude = [ + "libraries/libnbtplusplus" + ]; + }; - postUnpack = '' - ln -s ${libnbtplusplus} source/libraries/libnbtplusplus - ''; - - nativeBuildInputs = [ - cmake - ninja - extra-cmake-modules - jdk17 - stripJavaArchivesHook - ]; - - buildInputs = - [ - cmark - ghc_filesystem - kdePackages.qtbase - kdePackages.qtnetworkauth - kdePackages.quazip - libarchive - tomlplusplus - qrencode - zlib - ] - ++ lib.optionals stdenv.hostPlatform.isDarwin [ - darwin.apple_sdk.frameworks.Cocoa - ] - ++ lib.optional gamemodeSupport gamemode; + postUnpack = '' + ln -s ${libnbtplusplus} source/libraries/libnbtplusplus + ''; - cmakeFlags = - [ - (lib.cmakeFeature "Launcher_BUILD_PLATFORM" "nixpkgs") - ] - ++ lib.optionals (msaClientID != null) [ - (lib.cmakeFeature "Launcher_MSA_CLIENT_ID" (toString msaClientID)) - ] - ++ lib.optionals (lib.versionOlder kdePackages.qtbase.version "6") [ - (lib.cmakeFeature "Launcher_QT_VERSION_MAJOR" "5") - ] - ++ lib.optionals stdenv.hostPlatform.isDarwin [ - (lib.cmakeFeature "INSTALL_BUNDLE" "nodeps") - (lib.cmakeFeature "MACOSX_SPARKLE_UPDATE_FEED_URL" "''") - (lib.cmakeFeature "CMAKE_INSTALL_PREFIX" "${placeholder "out"}/Applications/") + nativeBuildInputs = [ + cmake + ninja + extra-cmake-modules + jdk17 + stripJavaArchivesHook ]; - doCheck = true; + buildInputs = + [ + cmark + ghc_filesystem + kdePackages.qtbase + kdePackages.qtnetworkauth + kdePackages.quazip + libarchive + tomlplusplus + qrencode + zlib + ] + ++ lib.optionals isDarwin [darwin.apple_sdk.frameworks.Cocoa] + ++ lib.optionals gamemodeSupport [gamemode]; - dontWrapQtApps = true; + cmakeFlags = + [(lib.cmakeFeature "Launcher_BUILD_PLATFORM" "nixpkgs")] + ++ lib.optionals (msaClientID != null) [ + (lib.cmakeFeature "Launcher_MSA_CLIENT_ID" msaClientID) + ] + ++ lib.optionals (lib.versionOlder kdePackages.qtbase.version "6") + [ + (lib.cmakeFeature "Launcher_QT_VERSION_MAJOR" "5") + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + (lib.cmakeFeature "INSTALL_BUNDLE" "nodeps") + (lib.cmakeFeature "MACOSX_SPARKLE_UPDATE_FEED_URL" "''") + (lib.cmakeFeature "CMAKE_INSTALL_PREFIX" "${placeholder "out"}/Applications/") + ]; - meta = { - description = "Prism Launcher fork aimed to provide a free way to play Minecraft"; - homepage = "https://freesmlauncher.org/"; - platforms = lib.platforms.linux ++ lib.platforms.darwin; - mainProgram = "freesmlauncher"; - license = lib.licenses.gpl3Only; - longDescription = '' - Freesm Launcher is a custom launcher for Minecraft that allows you - to easily manage multiple installations of Minecraft at once and login - with offline account without any restrictions. - ''; - maintainers = with lib.maintainers; [ - s0me1newithhand7s - ]; - }; - } + doCheck = true; + dontWrapQtApps = true; + enableParallelBuilding = true; + + meta = { + description = "Prism Launcher fork aimed to provide a free way to play Minecraft"; + longDescription = '' + Freesm Launcher is a custom launcher for Minecraft that allows you + to easily manage multiple installations of Minecraft at once and login + with offline account without any restrictions. + ''; + homepage = "https://freesmlauncher.org/"; + license = lib.licenses.gpl3Only; + platforms = lib.platforms.linux ++ lib.platforms.darwin; + mainProgram = "freesmlauncher"; + maintainers = with lib.maintainers; [s0me1newithhand7s]; + }; + } diff --git a/nix/wrapper.nix b/nix/wrapper.nix index 3469211c8..54b22a5c1 100644 --- a/nix/wrapper.nix +++ b/nix/wrapper.nix @@ -1,5 +1,10 @@ { + lib, + symlinkJoin, + kdePackages, addDriverRunpath, + freesmlauncher-unwrapped, + stdenv, alsa-lib, flite, gamemode, @@ -8,8 +13,6 @@ jdk21, jdk25, jdk8, - kdePackages, - lib, libGL, libX11, libXcursor, @@ -23,25 +26,19 @@ openal, pciutils, pipewire, - freesmlauncher-unwrapped, - clangStdenv, - stdenv ? clangStdenv, - symlinkJoin, udev, vulkan-loader, xrandr, - additionalLibs ? [], - additionalPrograms ? [], + msaClientID ? null, controllerSupport ? stdenv.hostPlatform.isLinux, gamemodeSupport ? stdenv.hostPlatform.isLinux, + textToSpeechSupport ? stdenv.hostPlatform.isLinux, jdks ? [ jdk25 jdk21 jdk17 jdk8 ], - msaClientID ? null, - textToSpeechSupport ? stdenv.hostPlatform.isLinux, }: assert lib.assertMsg ( controllerSupport -> stdenv.hostPlatform.isLinux @@ -49,95 +46,56 @@ assert lib.assertMsg ( assert lib.assertMsg ( textToSpeechSupport -> stdenv.hostPlatform.isLinux ) "textToSpeechSupport only has an effect on Linux."; let - freesmlauncher' = freesmlauncher-unwrapped.override {inherit msaClientID gamemodeSupport;}; -in - symlinkJoin { - pname = "freesmlauncher-${freesmlauncher'.version}"; - inherit - (freesmlauncher') - version - ; - - paths = [ - freesmlauncher' - ]; - - nativeBuildInputs = [ - kdePackages.wrapQtAppsHook - ]; + isLinux = stdenv.hostPlatform.isLinux; - buildInputs = - [ - kdePackages.qtbase - kdePackages.qtsvg - ] - ++ lib.optional ( - lib.versionAtLeast kdePackages.qtbase.version "6" && stdenv.hostPlatform.isLinux - ) - kdePackages.qtwayland; + launcher = freesmlauncher-unwrapped.override { + inherit msaClientID gamemodeSupport; + }; - postBuild = '' - wrapQtAppsHook - ''; + runtimePrograms = [mesa-demos pciutils xrandr]; + runtimeLibs = + [ + stdenv.cc.cc.lib - qtWrapperArgs = let - runtimeLibs = - [ - stdenv.cc.cc.lib - ## native versions - glfw3-minecraft - openal + glfw3-minecraft + openal - ## openal - alsa-lib - libjack2 - libpulseaudio - pipewire + alsa-lib + libjack2 + libpulseaudio + pipewire - ## glfw - libGL - libX11 - libXcursor - libXext - libXrandr - libXxf86vm + libGL + libX11 + libXcursor + libXext + libXrandr + libXxf86vm - udev # oshi + udev + vulkan-loader + ] + ++ lib.optionals textToSpeechSupport [flite] + ++ lib.optionals gamemodeSupport [gamemode.lib] + ++ lib.optionals controllerSupport [libusb1]; +in + symlinkJoin { + pname = "freesmlauncher"; + inherit (launcher) version meta; + paths = [launcher]; + nativeBuildInputs = [kdePackages.wrapQtAppsHook]; + buildInputs = with kdePackages; + [qtbase qtsvg] + ++ lib.optional (lib.versionAtLeast qtbase.version "6" && isLinux) qtwayland; - vulkan-loader # VulkanMod's lwjgl - ] - ++ lib.optional textToSpeechSupport flite - ++ lib.optional gamemodeSupport gamemode.lib - ++ lib.optional controllerSupport libusb1 - ++ additionalLibs; + postBuild = '' + wrapQtAppsHook + ''; - runtimePrograms = - [ - mesa-demos - pciutils # need lspci - xrandr # needed for LWJGL [2.9.2, 3) - ] - ++ additionalPrograms; - in - [ - "--prefix FREESMLAUNCHER_JAVA_PATHS : ${lib.makeSearchPath "bin/java" jdks}" - ] - ++ lib.optionals stdenv.hostPlatform.isLinux [ - "--set LD_LIBRARY_PATH ${addDriverRunpath.driverLink}/lib:${lib.makeLibraryPath runtimeLibs}" + qtWrapperArgs = + ["--prefix FREESMLAUNCHER_JAVA_PATHS : ${lib.makeSearchPath "bin/java" jdks}"] + ++ lib.optionals isLinux [ "--prefix PATH : ${lib.makeBinPath runtimePrograms}" + "--prefix LD_LIBRARY_PATH : ${addDriverRunpath.driverLink}/lib:${lib.makeLibraryPath runtimeLibs}" ]; - - meta = { - inherit - (freesmlauncher'.meta) - description - longDescription - homepage - changelog - license - maintainers - mainProgram - platforms - ; - }; }