From 687934433423b9d7c1014867f66f2bc73bd57c91 Mon Sep 17 00:00:00 2001 From: Evan Goode Date: Sat, 30 Nov 2024 17:29:26 -0500 Subject: [PATCH] chore(nix): nixfmt --- flake.nix | 187 ++++++++++++++++++++++++---------------------- nix/unwrapped.nix | 152 ++++++++++++++++++------------------- nix/wrapper.nix | 92 +++++++++++------------ 3 files changed, 219 insertions(+), 212 deletions(-) diff --git a/flake.nix b/flake.nix index ef2437f3e..6654e4309 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "Prism Launcher fork with support for alternative auth servers"; nixConfig = { - extra-substituters = ["https://unmojang.cachix.org"]; + extra-substituters = [ "https://unmojang.cachix.org" ]; extra-trusted-public-keys = [ "unmojang.cachix.org-1:OfHnbBNduZ6Smx9oNbLFbYyvOWSoxb2uPcnXPj4EDQY=" ]; @@ -19,18 +19,18 @@ nix-filter.url = "github:numtide/nix-filter"; /* - Inputs below this are optional and can be removed - - ``` - { - inputs.fjordlauncher = { - url = "github:unmojang/FjordLauncher"; - inputs = { - flake-compat.follows = ""; + Inputs below this are optional and can be removed + + ``` + { + inputs.fjordlauncher = { + url = "github:unmojang/FjordLauncher"; + inputs = { + flake-compat.follows = ""; + }; }; - }; - } - ``` + } + ``` */ flake-compat = { @@ -39,90 +39,99 @@ }; }; - outputs = { - self, - nixpkgs, - libnbtplusplus, - nix-filter, - ... - }: let - inherit (nixpkgs) lib; - - # While we only officially support aarch and x86_64 on Linux and MacOS, - # we expose a reasonable amount of other systems for users who want to - # build for most exotic platforms - systems = lib.systems.flakeExposed; - - forAllSystems = lib.genAttrs systems; - nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system}); - in { - checks = forAllSystems ( - system: let - checks' = nixpkgsFor.${system}.callPackage ./nix/checks.nix {inherit self;}; - in + outputs = + { + self, + nixpkgs, + libnbtplusplus, + nix-filter, + ... + }: + let + inherit (nixpkgs) lib; + + # While we only officially support aarch and x86_64 on Linux and MacOS, + # we expose a reasonable amount of other systems for users who want to + # build for most exotic platforms + systems = lib.systems.flakeExposed; + + forAllSystems = lib.genAttrs systems; + nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system}); + in + { + checks = forAllSystems ( + system: + let + checks' = nixpkgsFor.${system}.callPackage ./nix/checks.nix { inherit self; }; + in lib.filterAttrs (_: lib.isDerivation) checks' - ); - - devShells = forAllSystems ( - system: let - pkgs = nixpkgsFor.${system}; - in { - default = pkgs.mkShell { - inputsFrom = [self.packages.${system}.fjordlauncher-unwrapped]; - buildInputs = with pkgs; [ - ccache - ninja - ]; + ); + + devShells = forAllSystems ( + system: + let + pkgs = nixpkgsFor.${system}; + in + { + default = pkgs.mkShell { + inputsFrom = [ self.packages.${system}.fjordlauncher-unwrapped ]; + buildInputs = with pkgs; [ + ccache + ninja + ]; + }; + } + ); + + formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style); + + overlays.default = final: prev: { + fjordlauncher-unwrapped = prev.callPackage ./nix/unwrapped.nix { + inherit + libnbtplusplus + nix-filter + self + ; }; - } - ); - formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style); - - overlays.default = final: prev: { - fjordlauncher-unwrapped = prev.callPackage ./nix/unwrapped.nix { - inherit - libnbtplusplus - nix-filter - self - ; + fjordlauncher = final.callPackage ./nix/wrapper.nix { }; }; - fjordlauncher = final.callPackage ./nix/wrapper.nix {}; - }; + packages = forAllSystems ( + system: + let + pkgs = nixpkgsFor.${system}; - packages = forAllSystems ( - system: let - pkgs = nixpkgsFor.${system}; + # Build a scope from our overlay + fjordPackages = lib.makeScope pkgs.newScope (final: self.overlays.default final pkgs); - # Build a scope from our overlay - fjordPackages = lib.makeScope pkgs.newScope (final: self.overlays.default final pkgs); - - # Grab our packages from it and set the default - packages = { - inherit (fjordPackages) fjordlauncher-unwrapped fjordlauncher; - default = fjordPackages.fjordlauncher; - }; - in + # Grab our packages from it and set the default + packages = { + inherit (fjordPackages) fjordlauncher-unwrapped fjordlauncher; + default = fjordPackages.fjordlauncher; + }; + in # Only output them if they're available on the current system lib.filterAttrs (_: lib.meta.availableOn pkgs.stdenv.hostPlatform) packages - ); - - # We put these under legacyPackages as they are meant for CI, not end user consumption - legacyPackages = forAllSystems ( - system: let - fjordPackages = self.packages.${system}; - legacyPackages = self.legacyPackages.${system}; - in { - fjordlauncher-debug = fjordPackages.fjordlauncher.override { - fjordlauncher-unwrapped = legacyPackages.fjordlauncher-unwrapped-debug; - }; - - fjordlauncher-unwrapped-debug = fjordPackages.fjordlauncher-unwrapped.overrideAttrs { - cmakeBuildType = "Debug"; - dontStrip = true; - }; - } - ); - }; + ); + + # We put these under legacyPackages as they are meant for CI, not end user consumption + legacyPackages = forAllSystems ( + system: + let + fjordPackages = self.packages.${system}; + legacyPackages = self.legacyPackages.${system}; + in + { + fjordlauncher-debug = fjordPackages.fjordlauncher.override { + fjordlauncher-unwrapped = legacyPackages.fjordlauncher-unwrapped-debug; + }; + + fjordlauncher-unwrapped-debug = fjordPackages.fjordlauncher-unwrapped.overrideAttrs { + cmakeBuildType = "Debug"; + dontStrip = true; + }; + } + ); + }; } diff --git a/nix/unwrapped.nix b/nix/unwrapped.nix index 4f6c7181e..4dd24379d 100644 --- a/nix/unwrapped.nix +++ b/nix/unwrapped.nix @@ -22,88 +22,88 @@ assert lib.assertMsg ( gamemodeSupport -> stdenv.hostPlatform.isLinux ) "gamemodeSupport is only available on Linux."; - stdenv.mkDerivation { - pname = "fjordlauncher-unwrapped"; - version = self.shortRev or self.dirtyShortRev or "unknown"; +stdenv.mkDerivation { + pname = "fjordlauncher-unwrapped"; + version = self.shortRev or self.dirtyShortRev or "unknown"; - src = nix-filter.lib { - root = self; - include = [ - "buildconfig" - "cmake" - "launcher" - "libraries" - "program_info" - "tests" - ../COPYING.md - ../CMakeLists.txt - ]; - }; + src = nix-filter.lib { + root = self; + include = [ + "buildconfig" + "cmake" + "launcher" + "libraries" + "program_info" + "tests" + ../COPYING.md + ../CMakeLists.txt + ]; + }; - postUnpack = '' - rm -rf source/libraries/libnbtplusplus - ln -s ${libnbtplusplus} source/libraries/libnbtplusplus - ''; + postUnpack = '' + rm -rf source/libraries/libnbtplusplus + ln -s ${libnbtplusplus} source/libraries/libnbtplusplus + ''; - nativeBuildInputs = [ - cmake - ninja - extra-cmake-modules - jdk17 - stripJavaArchivesHook - ]; + nativeBuildInputs = [ + cmake + ninja + extra-cmake-modules + jdk17 + stripJavaArchivesHook + ]; - buildInputs = - [ - cmark - ghc_filesystem - kdePackages.qtbase - kdePackages.qtnetworkauth - kdePackages.quazip - tomlplusplus - zlib - ] - ++ lib.optionals stdenv.hostPlatform.isDarwin [apple-sdk_11] - ++ lib.optional gamemodeSupport gamemode; + buildInputs = + [ + cmark + ghc_filesystem + kdePackages.qtbase + kdePackages.qtnetworkauth + kdePackages.quazip + tomlplusplus + zlib + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ apple-sdk_11 ] + ++ lib.optional gamemodeSupport gamemode; - hardeningEnable = lib.optionals stdenv.hostPlatform.isLinux ["pie"]; + hardeningEnable = lib.optionals stdenv.hostPlatform.isLinux [ "pie" ]; - cmakeFlags = - [ - # downstream branding - (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 [ - # 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/") - ]; + cmakeFlags = + [ + # downstream branding + (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 [ + # 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; + doCheck = true; - dontWrapQtApps = true; + dontWrapQtApps = true; - meta = { - description = "Prism Launcher fork with support for alternative auth servers"; - 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://github.com/unmojang/FjordLauncher"; - license = lib.licenses.gpl3Only; - maintainers = with lib.maintainers; [ - evan-goode - ]; - mainProgram = "fjordlauncher"; - platforms = lib.platforms.linux ++ lib.platforms.darwin; - }; - } + meta = { + description = "Prism Launcher fork with support for alternative auth servers"; + 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://github.com/unmojang/FjordLauncher"; + license = lib.licenses.gpl3Only; + maintainers = with lib.maintainers; [ + evan-goode + ]; + mainProgram = "fjordlauncher"; + platforms = lib.platforms.linux ++ lib.platforms.darwin; + }; +} diff --git a/nix/wrapper.nix b/nix/wrapper.nix index 835731cc3..8e5111a18 100644 --- a/nix/wrapper.nix +++ b/nix/wrapper.nix @@ -28,8 +28,8 @@ udev, vulkan-loader, xrandr, - additionalLibs ? [], - additionalPrograms ? [], + additionalLibs ? [ ], + additionalPrograms ? [ ], controllerSupport ? stdenv.hostPlatform.isLinux, gamemodeSupport ? stdenv.hostPlatform.isLinux, jdks ? [ @@ -45,31 +45,32 @@ assert lib.assertMsg ( ) "controllerSupport only has an effect on Linux."; assert lib.assertMsg ( textToSpeechSupport -> stdenv.hostPlatform.isLinux -) "textToSpeechSupport only has an effect on Linux."; let - fjordlauncher' = fjordlauncher-unwrapped.override {inherit msaClientID gamemodeSupport;}; +) "textToSpeechSupport only has an effect on Linux."; +let + fjordlauncher' = fjordlauncher-unwrapped.override { inherit msaClientID gamemodeSupport; }; in - symlinkJoin { - name = "fjordlauncher-${fjordlauncher'.version}"; +symlinkJoin { + name = "fjordlauncher-${fjordlauncher'.version}"; - paths = [fjordlauncher']; + paths = [ fjordlauncher' ]; - nativeBuildInputs = [kdePackages.wrapQtAppsHook]; + nativeBuildInputs = [ kdePackages.wrapQtAppsHook ]; - buildInputs = - [ - kdePackages.qtbase - kdePackages.qtsvg - ] - ++ lib.optional ( - lib.versionAtLeast kdePackages.qtbase.version "6" && stdenv.hostPlatform.isLinux - ) - kdePackages.qtwayland; + buildInputs = + [ + kdePackages.qtbase + kdePackages.qtsvg + ] + ++ lib.optional ( + lib.versionAtLeast kdePackages.qtbase.version "6" && stdenv.hostPlatform.isLinux + ) kdePackages.qtwayland; - postBuild = '' - wrapQtAppsHook - ''; + postBuild = '' + wrapQtAppsHook + ''; - qtWrapperArgs = let + qtWrapperArgs = + let runtimeLibs = [ (lib.getLib stdenv.cc.cc) @@ -100,31 +101,28 @@ in ++ 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; + runtimePrograms = [ + mesa-demos + pciutils # need lspci + xrandr # needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128 + ] ++ additionalPrograms; in - ["--prefix FJORDLAUNCHER_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}" - ]; + [ "--prefix FJORDLAUNCHER_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 - (fjordlauncher'.meta) - description - longDescription - homepage - changelog - license - maintainers - mainProgram - platforms - ; - }; - } + meta = { + inherit (fjordlauncher'.meta) + description + longDescription + homepage + changelog + license + maintainers + mainProgram + platforms + ; + }; +}