From 4c81d8c53d09196426568c4a31a4e752ed05397a Mon Sep 17 00:00:00 2001 From: seth Date: Tue, 20 Aug 2024 01:44:24 -0400 Subject: [PATCH] style(nix): format with nixfmt Signed-off-by: seth --- default.nix | 23 +++---- flake.nix | 13 ++-- nix/README.md | 72 ++++++++++++++-------- nix/dev.nix | 67 ++++++++++++--------- nix/distribution.nix | 54 ++++++++--------- nix/pkg/default.nix | 140 ++++++++++++++++++++++--------------------- nix/pkg/wrapper.nix | 126 +++++++++++++++++++------------------- 7 files changed, 259 insertions(+), 236 deletions(-) diff --git a/default.nix b/default.nix index c7d0c267d..6466507b7 100644 --- a/default.nix +++ b/default.nix @@ -1,14 +1,9 @@ -( - 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 +(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.nix b/flake.nix index 7cef5217a..1e3e36d66 100644 --- a/flake.nix +++ b/flake.nix @@ -2,8 +2,8 @@ description = "A custom launcher for Minecraft that allows you to easily manage multiple installations of Minecraft at once (Fork of MultiMC)"; nixConfig = { - extra-substituters = ["https://cache.garnix.io"]; - extra-trusted-public-keys = ["cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g="]; + extra-substituters = [ "https://cache.garnix.io" ]; + extra-trusted-public-keys = [ "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ]; }; inputs = { @@ -30,12 +30,9 @@ }; }; - outputs = { - flake-parts, - pre-commit-hooks, - ... - } @ inputs: - flake-parts.lib.mkFlake {inherit inputs;} { + outputs = + { flake-parts, pre-commit-hooks, ... }@inputs: + flake-parts.lib.mkFlake { inherit inputs; } { imports = [ pre-commit-hooks.flakeModule diff --git a/nix/README.md b/nix/README.md index f7923577f..8a0b9ba26 100644 --- a/nix/README.md +++ b/nix/README.md @@ -15,7 +15,6 @@ to temporarily enable it when using `nix` commands. Example (NixOS): ```nix -{...}: { nix.settings = { trusted-substituters = [ @@ -39,6 +38,7 @@ Example: { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + prismlauncher = { url = "github:PrismLauncher/PrismLauncher"; # Optional: Override the nixpkgs input of prismlauncher to use the same revision as the rest of your flake @@ -47,19 +47,24 @@ Example: }; }; - outputs = {nixpkgs, prismlauncher}: { - nixosConfigurations.foo = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; + outputs = + { nixpkgs, prismlauncher }: + { + nixosConfigurations.foo = nixpkgs.lib.nixosSystem { + modules = [ + ./configuration.nix - modules = [ - ({pkgs, ...}: { - nixpkgs.overlays = [prismlauncher.overlays.default]; + ( + { pkgs, ... }: + { + nixpkgs.overlays = [ prismlauncher.overlays.default ]; - environment.systemPackages = [pkgs.prismlauncher]; - }) - ]; + environment.systemPackages = [ pkgs.prismlauncher ]; + } + ) + ]; + }; }; - } } ``` @@ -74,6 +79,7 @@ Example: { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + prismlauncher = { url = "github:PrismLauncher/PrismLauncher"; # Optional: Override the nixpkgs input of prismlauncher to use the same revision as the rest of your flake @@ -82,17 +88,22 @@ Example: }; }; - outputs = {nixpkgs, prismlauncher}: { - nixosConfigurations.foo = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; + outputs = + { nixpkgs, prismlauncher }: + { + nixosConfigurations.foo = nixpkgs.lib.nixosSystem { + modules = [ + ./configuration.nix - modules = [ - ({pkgs, ...}: { - environment.systemPackages = [prismlauncher.packages.${pkgs.system}.prismlauncher]; - }) - ]; + ( + { pkgs, ... }: + { + environment.systemPackages = [ prismlauncher.packages.${pkgs.system}.prismlauncher ]; + } + ) + ]; + }; }; - } } ``` @@ -118,7 +129,6 @@ If you want to avoid rebuilds you may add the garnix cache to your substitutors. Example (NixOS): ```nix -{...}: { nix.settings = { trusted-substituters = [ @@ -139,10 +149,15 @@ We use flake-compat to allow using this Flake on a system that doesn't use flake Example: ```nix -{pkgs, ...}: { - nixpkgs.overlays = [(import (builtins.fetchTarball "https://github.com/PrismLauncher/PrismLauncher/archive/develop.tar.gz")).overlays.default]; +{ pkgs, ... }: +{ + nixpkgs.overlays = [ + (import ( + builtins.fetchTarball "https://github.com/PrismLauncher/PrismLauncher/archive/develop.tar.gz" + )).overlays.default + ]; - environment.systemPackages = [pkgs.prismlauncher]; + environment.systemPackages = [ pkgs.prismlauncher ]; } ``` @@ -154,8 +169,13 @@ This way the installed package is fully reproducible. Example: ```nix -{pkgs, ...}: { - environment.systemPackages = [(import (builtins.fetchTarball "https://github.com/PrismLauncher/PrismLauncher/archive/develop.tar.gz")).packages.${pkgs.system}.prismlauncher]; +{ pkgs, ... }: +{ + environment.systemPackages = [ + (import ( + builtins.fetchTarball "https://github.com/PrismLauncher/PrismLauncher/archive/develop.tar.gz" + )).packages.${pkgs.system}.prismlauncher + ]; } ``` diff --git a/nix/dev.nix b/nix/dev.nix index 22b4b43fb..2ae3c845b 100644 --- a/nix/dev.nix +++ b/nix/dev.nix @@ -1,36 +1,47 @@ { - perSystem = { - config, - lib, - pkgs, - ... - }: { - pre-commit.settings = { - hooks = { - markdownlint.enable = true; + perSystem = + { + config, + lib, + pkgs, + ... + }: + { + pre-commit.settings = { + hooks = { + markdownlint.enable = true; - deadnix.enable = true; - nil.enable = true; - nixfmt.enable = true; + deadnix.enable = true; + nil.enable = true; + nixfmt.enable = true; - clang-format = { - enable = true; - types_or = ["c" "c++" "java" "json" "objective-c"]; + clang-format = { + enable = true; + types_or = [ + "c" + "c++" + "java" + "json" + "objective-c" + ]; + }; }; + + tools.clang-tools = lib.mkForce pkgs.clang-tools_18; }; - tools.clang-tools = lib.mkForce pkgs.clang-tools_18; + devShells.default = pkgs.mkShell { + shellHook = '' + ${config.pre-commit.installationScript} + ''; + + inputsFrom = [ config.packages.prismlauncher-unwrapped ]; + buildInputs = with pkgs; [ + ccache + ninja + ]; + }; + + formatter = pkgs.nixfmt-rfc-style; }; - - devShells.default = pkgs.mkShell { - shellHook = '' - ${config.pre-commit.installationScript} - ''; - - inputsFrom = [config.packages.prismlauncher-unwrapped]; - buildInputs = with pkgs; [ccache ninja]; - }; - - formatter = pkgs.nixfmt-rfc-style; - }; } diff --git a/nix/distribution.nix b/nix/distribution.nix index 28ef7ced1..ac7fc9871 100644 --- a/nix/distribution.nix +++ b/nix/distribution.nix @@ -1,37 +1,33 @@ +{ inputs, self, ... }: { - inputs, - self, - ... -}: { - perSystem = { - lib, - pkgs, - ... - }: { - packages = let - ourPackages = lib.fix (final: self.overlays.default final pkgs); - in { - inherit - (ourPackages) - prismlauncher-unwrapped - prismlauncher - ; - default = ourPackages.prismlauncher; + perSystem = + { lib, pkgs, ... }: + { + packages = + let + ourPackages = lib.fix (final: self.overlays.default final pkgs); + in + { + inherit (ourPackages) prismlauncher-unwrapped prismlauncher; + default = ourPackages.prismlauncher; + }; }; - }; flake = { - overlays.default = final: prev: let - version = builtins.substring 0 8 self.lastModifiedDate or "dirty"; - in { - prismlauncher-unwrapped = prev.callPackage ./pkg { - inherit (inputs) libnbtplusplus; - inherit version; - }; + overlays.default = + final: prev: + let + version = builtins.substring 0 8 self.lastModifiedDate or "dirty"; + in + { + prismlauncher-unwrapped = prev.callPackage ./pkg { + inherit (inputs) libnbtplusplus; + inherit version; + }; - prismlauncher = prev.qt6Packages.callPackage ./pkg/wrapper.nix { - inherit (final) prismlauncher-unwrapped; + prismlauncher = prev.qt6Packages.callPackage ./pkg/wrapper.nix { + inherit (final) prismlauncher-unwrapped; + }; }; - }; }; } diff --git a/nix/pkg/default.nix b/nix/pkg/default.nix index f3ff3789c..a5a57eaf0 100644 --- a/nix/pkg/default.nix +++ b/nix/pkg/default.nix @@ -18,16 +18,19 @@ version, libnbtplusplus, }: + assert lib.assertMsg ( gamemodeSupport -> stdenv.isLinux ) "gamemodeSupport is only available on Linux."; - stdenv.mkDerivation { - pname = "prismlauncher-unwrapped"; - inherit version; - src = lib.fileset.toSource { - root = ../../.; - fileset = lib.fileset.unions (map (fileName: ../../${fileName}) [ +stdenv.mkDerivation { + pname = "prismlauncher-unwrapped"; + inherit version; + + src = lib.fileset.toSource { + root = ../../.; + fileset = lib.fileset.unions ( + map (fileName: ../../${fileName}) [ "buildconfig" "cmake" "launcher" @@ -36,71 +39,70 @@ assert lib.assertMsg ( "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.isDarwin [ darwin.apple_sdk.frameworks.Cocoa ] + ++ lib.optional gamemodeSupport gamemode; + + hardeningEnable = lib.optionals stdenv.isLinux [ "pie" ]; + + 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.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/") ]; - buildInputs = - [ - cmark - ghc_filesystem - kdePackages.qtbase - kdePackages.qtnetworkauth - kdePackages.quazip - tomlplusplus - zlib - ] - ++ lib.optionals stdenv.isDarwin [darwin.apple_sdk.frameworks.Cocoa] - ++ lib.optional gamemodeSupport gamemode; + dontWrapQtApps = true; - hardeningEnable = lib.optionals stdenv.isLinux ["pie"]; - - 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.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/") - ]; - - 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://prismlauncher.org/"; - license = lib.licenses.gpl3Only; - maintainers = with lib.maintainers; [ - Scrumplex - getchoo - ]; - mainProgram = "prismlauncher"; - platforms = lib.platforms.linux ++ lib.platforms.darwin; - }; - } + 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://prismlauncher.org/"; + license = lib.licenses.gpl3Only; + maintainers = with lib.maintainers; [ + Scrumplex + getchoo + ]; + mainProgram = "prismlauncher"; + platforms = lib.platforms.linux ++ lib.platforms.darwin; + }; +} diff --git a/nix/pkg/wrapper.nix b/nix/pkg/wrapper.nix index e7516397e..5632d483b 100644 --- a/nix/pkg/wrapper.nix +++ b/nix/pkg/wrapper.nix @@ -22,8 +22,8 @@ udev, vulkan-loader, xorg, - additionalLibs ? [], - additionalPrograms ? [], + additionalLibs ? [ ], + additionalPrograms ? [ ], controllerSupport ? stdenv.isLinux, gamemodeSupport ? stdenv.isLinux, jdks ? [ @@ -42,55 +42,60 @@ # 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 - prismlauncher' = prismlauncher-unwrapped.override {inherit msaClientID gamemodeSupport;}; +) "withWaylandGLFW is only available on Linux."; + +let + prismlauncher' = prismlauncher-unwrapped.override { inherit msaClientID gamemodeSupport; }; in - symlinkJoin { - name = "prismlauncher-${prismlauncher'.version}"; +symlinkJoin { + name = "prismlauncher-${prismlauncher'.version}"; - paths = [prismlauncher']; + paths = [ prismlauncher' ]; - nativeBuildInputs = - [kdePackages.wrapQtAppsHook] - # purposefully using a shell wrapper here for variable expansion - # see https://github.com/NixOS/nixpkgs/issues/172583 - ++ lib.optional withWaylandGLFW makeWrapper; + nativeBuildInputs = + [ kdePackages.wrapQtAppsHook ] + # purposefully using a shell wrapper here for variable expansion + # see https://github.com/NixOS/nixpkgs/issues/172583 + ++ lib.optional withWaylandGLFW makeWrapper; - buildInputs = - [ - kdePackages.qtbase - kdePackages.qtsvg - ] - ++ lib.optional ( - lib.versionAtLeast kdePackages.qtbase.version "6" && stdenv.isLinux - ) - kdePackages.qtwayland; + 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 - ''; - }; + 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 - ''; + postBuild = + lib.optionalString withWaylandGLFW '' + qtWrapperArgs+=(--run "$waylandPreExec") + '' + + '' + wrapQtAppsHook + ''; - qtWrapperArgs = let + qtWrapperArgs = + let runtimeLibs = [ # lwjgl @@ -115,31 +120,28 @@ in ++ lib.optional controllerSupport libusb1 ++ additionalLibs; - runtimePrograms = - [ - glxinfo - pciutils # need lspci - xorg.xrandr # needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128 - ] - ++ 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}" - "--prefix PATH : ${lib.makeBinPath runtimePrograms}" - ]; + [ "--prefix PRISMLAUNCHER_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 - (prismlauncher'.meta) - description - longDescription - homepage - changelog - license - maintainers - mainProgram - platforms - ; - }; - } + meta = { + inherit (prismlauncher'.meta) + description + longDescription + homepage + changelog + license + maintainers + mainProgram + platforms + ; + }; +}