From b5fc23952ea99d7f3eac62714e4937cf9da31074 Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Sun, 30 Mar 2025 16:41:19 -0400 Subject: [PATCH 01/11] Reapply "refactor(nix): nix-filter -> lib.fileset" After extensive (5 minutes) of testing, it seems we don't actually come across any Nix bugs with lib.fileset! (aside from those inherit to it...but :shrug:) This reverts commit a49a58bc4571f87f42f45bb9eeb1a957d5d12331. Signed-off-by: Seth Flynn (cherry picked from commit 99852c972c6e9fc6a8caca727946a71a85c1672f) --- flake.lock | 39 +++------------------------------------ flake.nix | 4 ---- nix/unwrapped.nix | 22 +++++++++++----------- 3 files changed, 14 insertions(+), 51 deletions(-) diff --git a/flake.lock b/flake.lock index a82e6f65f..d8c7c5248 100644 --- a/flake.lock +++ b/flake.lock @@ -1,21 +1,5 @@ { "nodes": { - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1696426674, - "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, "libnbtplusplus": { "flake": false, "locked": { @@ -32,28 +16,13 @@ "type": "github" } }, - "nix-filter": { - "locked": { - "lastModified": 1710156097, - "narHash": "sha256-1Wvk8UP7PXdf8bCCaEoMnOT1qe5/Duqgj+rL8sRQsSM=", - "owner": "numtide", - "repo": "nix-filter", - "rev": "3342559a24e85fc164b295c3444e8a139924675b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "nix-filter", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1729256560, - "narHash": "sha256-/uilDXvCIEs3C9l73JTACm4quuHUsIHcns1c+cHUJwA=", + "lastModified": 1743095683, + "narHash": "sha256-gWd4urRoLRe8GLVC/3rYRae1h+xfQzt09xOfb0PaHSk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4c2fcb090b1f3e5b47eaa7bd33913b574a11e0a0", + "rev": "5e5402ecbcb27af32284d4a62553c019a3a49ea6", "type": "github" }, "original": { @@ -65,9 +34,7 @@ }, "root": { "inputs": { - "flake-compat": "flake-compat", "libnbtplusplus": "libnbtplusplus", - "nix-filter": "nix-filter", "nixpkgs": "nixpkgs" } } diff --git a/flake.nix b/flake.nix index 54add656d..f8954af23 100644 --- a/flake.nix +++ b/flake.nix @@ -16,8 +16,6 @@ flake = false; }; - nix-filter.url = "github:numtide/nix-filter"; - /* Inputs below this are optional and can be removed @@ -44,7 +42,6 @@ self, nixpkgs, libnbtplusplus, - nix-filter, ... }: let @@ -89,7 +86,6 @@ prismlauncher-unwrapped = prev.callPackage ./nix/unwrapped.nix { inherit libnbtplusplus - nix-filter self ; }; diff --git a/nix/unwrapped.nix b/nix/unwrapped.nix index 1b14886ef..f47051287 100644 --- a/nix/unwrapped.nix +++ b/nix/unwrapped.nix @@ -11,7 +11,6 @@ kdePackages, libnbtplusplus, ninja, - nix-filter, self, stripJavaArchivesHook, tomlplusplus, @@ -29,17 +28,18 @@ stdenv.mkDerivation { pname = "prismlauncher-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 + src = lib.fileset.toSource { + root = ../.; + fileset = lib.fileset.unions [ ../CMakeLists.txt + ../COPYING.md + + ../buildconfig + ../cmake + ../launcher + ../libraries + ../program_info + ../tests ]; }; From 80ff62c96d19fa9fe2d4446267ce1cb9cc22459a Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Sun, 30 Mar 2025 16:43:49 -0400 Subject: [PATCH 02/11] refactor(nix): pin flake-compat in default.nix Avoids polluting downstream flake.locks Signed-off-by: Seth Flynn (cherry picked from commit c367f48ec99f048f8d4bcaf0634370be33b29c62) --- default.nix | 13 ++++--------- flake.nix | 20 -------------------- nix/README.md | 6 ------ 3 files changed, 4 insertions(+), 35 deletions(-) diff --git a/default.nix b/default.nix index 6466507b7..5ecef5590 100644 --- a/default.nix +++ b/default.nix @@ -1,9 +1,4 @@ -(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 (fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/ff81ac966bb2cae68946d5ed5fc4994f96d0ffec.tar.gz"; + sha256 = "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU="; +}) { src = ./.; }).defaultNix diff --git a/flake.nix b/flake.nix index f8954af23..153cf7c77 100644 --- a/flake.nix +++ b/flake.nix @@ -15,26 +15,6 @@ url = "github:PrismLauncher/libnbtplusplus"; flake = false; }; - - /* - Inputs below this are optional and can be removed - - ``` - { - inputs.prismlauncher = { - url = "github:PrismLauncher/PrismLauncher"; - inputs = { - flake-compat.follows = ""; - }; - }; - } - ``` - */ - - flake-compat = { - url = "github:edolstra/flake-compat"; - flake = false; - }; }; outputs = diff --git a/nix/README.md b/nix/README.md index 8bb658477..041a20519 100644 --- a/nix/README.md +++ b/nix/README.md @@ -44,9 +44,6 @@ Example: # Note that this may break the reproducibility mentioned above, and you might not be able to access the binary cache # # inputs.nixpkgs.follows = "nixpkgs"; - - # This is not required for Flakes - inputs.flake-compat.follows = ""; }; }; @@ -92,9 +89,6 @@ Example: # Note that this may break the reproducibility mentioned above, and you might not be able to access the binary cache # # inputs.nixpkgs.follows = "nixpkgs"; - - # This is not required for Flakes - inputs.flake-compat.follows = ""; }; }; From 87c5b6cc831f5ddfd38fe5307246eea29d79b94d Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Sun, 30 Mar 2025 17:11:51 -0400 Subject: [PATCH 03/11] refactor(nix): cleanup flake Signed-off-by: Seth Flynn (cherry picked from commit 32b49ecb84da5683bce42e2e888319f4517f1d53) --- flake.nix | 78 +++++++++++++++++++++++++++++++++++++++++++------- nix/checks.nix | 42 --------------------------- 2 files changed, 67 insertions(+), 53 deletions(-) delete mode 100644 nix/checks.nix diff --git a/flake.nix b/flake.nix index 153cf7c77..ea14f9048 100644 --- a/flake.nix +++ b/flake.nix @@ -22,8 +22,8 @@ self, nixpkgs, libnbtplusplus, - ... }: + let inherit (nixpkgs) lib; @@ -35,27 +35,79 @@ forAllSystems = lib.genAttrs systems; nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system}); in + { checks = forAllSystems ( system: + let - checks' = nixpkgsFor.${system}.callPackage ./nix/checks.nix { inherit self; }; + pkgs = nixpkgsFor.${system}; + llvm = pkgs.llvmPackages_19; in - lib.filterAttrs (_: lib.isDerivation) checks' + + { + formatting = + pkgs.runCommand "check-formatting" + { + nativeBuildInputs = with pkgs; [ + deadnix + llvm.clang-tools + markdownlint-cli + nixfmt-rfc-style + statix + ]; + } + '' + cd ${self} + + echo "Running clang-format...." + clang-format --dry-run --style='file' --Werror */**.{c,cc,cpp,h,hh,hpp} + + echo "Running deadnix..." + deadnix --fail + + echo "Running markdownlint..." + markdownlint --dot . + + echo "Running nixfmt..." + find -type f -name '*.nix' -exec nixfmt --check {} + + + echo "Running statix" + statix check . + + touch $out + ''; + } ); devShells = forAllSystems ( system: + let pkgs = nixpkgsFor.${system}; + llvm = pkgs.llvmPackages_19; + + packages' = self.packages.${system}; in + { default = pkgs.mkShell { - inputsFrom = [ self.packages.${system}.prismlauncher-unwrapped ]; - buildInputs = with pkgs; [ + inputsFrom = [ packages'.prismlauncher-unwrapped ]; + + nativeBuildInputs = with pkgs; [ ccache - ninja + llvm.clang-tools ]; + + cmakeFlags = packages'.prismlauncher-unwrapped.cmakeFlags ++ [ + "-GNinja" + "-Bbuild" + ]; + + shellHook = '' + cmake $cmakeFlags -D CMAKE_BUILD_TYPE=Debug + ln -s {build/,}compile_commands.json + ''; }; } ); @@ -75,6 +127,7 @@ packages = forAllSystems ( system: + let pkgs = nixpkgsFor.${system}; @@ -87,6 +140,7 @@ default = prismPackages.prismlauncher; }; in + # Only output them if they're available on the current system lib.filterAttrs (_: lib.meta.availableOn pkgs.stdenv.hostPlatform) packages ); @@ -94,16 +148,18 @@ # We put these under legacyPackages as they are meant for CI, not end user consumption legacyPackages = forAllSystems ( system: + let - prismPackages = self.packages.${system}; - legacyPackages = self.legacyPackages.${system}; + packages' = self.packages.${system}; + legacyPackages' = self.legacyPackages.${system}; in + { - prismlauncher-debug = prismPackages.prismlauncher.override { - prismlauncher-unwrapped = legacyPackages.prismlauncher-unwrapped-debug; + prismlauncher-debug = packages'.prismlauncher.override { + prismlauncher-unwrapped = legacyPackages'.prismlauncher-unwrapped-debug; }; - prismlauncher-unwrapped-debug = prismPackages.prismlauncher-unwrapped.overrideAttrs { + prismlauncher-unwrapped-debug = packages'.prismlauncher-unwrapped.overrideAttrs { cmakeBuildType = "Debug"; dontStrip = true; }; diff --git a/nix/checks.nix b/nix/checks.nix deleted file mode 100644 index ec219d6f8..000000000 --- a/nix/checks.nix +++ /dev/null @@ -1,42 +0,0 @@ -{ - runCommand, - deadnix, - llvmPackages_18, - markdownlint-cli, - nixfmt-rfc-style, - statix, - self, -}: -{ - formatting = - runCommand "check-formatting" - { - nativeBuildInputs = [ - deadnix - llvmPackages_18.clang-tools - markdownlint-cli - nixfmt-rfc-style - statix - ]; - } - '' - cd ${self} - - echo "Running clang-format...." - clang-format --dry-run --style='file' --Werror */**.{c,cc,cpp,h,hh,hpp} - - echo "Running deadnix..." - deadnix --fail - - echo "Running markdownlint..." - markdownlint --dot . - - echo "Running nixfmt..." - nixfmt --check . - - echo "Running statix" - statix check . - - touch $out - ''; -} From 5c4bd3db52b927f9a4ccd8cb4f1fe7c7d7a8f374 Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Sun, 30 Mar 2025 17:19:20 -0400 Subject: [PATCH 04/11] fix(nix): only create compile_commands.json if it doesn't exist Signed-off-by: Seth Flynn (cherry picked from commit 58579539d071c569800ba0370a6d5918de025e33) --- flake.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index ea14f9048..ceb4bad4b 100644 --- a/flake.nix +++ b/flake.nix @@ -105,8 +105,10 @@ ]; shellHook = '' - cmake $cmakeFlags -D CMAKE_BUILD_TYPE=Debug - ln -s {build/,}compile_commands.json + if [ ! -f compile_commands.json ]; then + cmake $cmakeFlags -D CMAKE_BUILD_TYPE=Debug + ln -s {build/,}compile_commands.json + fi ''; }; } From 760fbdf54fd561dee40a3b378f0b7ab7cc9e2270 Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Sun, 30 Mar 2025 18:41:06 -0400 Subject: [PATCH 05/11] build(nix): properly wrap development shell Allows actually running the executables built in the development shell Signed-off-by: Seth Flynn (cherry picked from commit 2d4bc09cb9bec621997e00c23acac0b7cf3e99d7) --- flake.nix | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index ceb4bad4b..55d8b0464 100644 --- a/flake.nix +++ b/flake.nix @@ -88,13 +88,35 @@ llvm = pkgs.llvmPackages_19; packages' = self.packages.${system}; + + # Re-use our package wrapper to wrap our development environment + qt-wrapper-env = packages'.prismlauncher.overrideAttrs (old: { + name = "qt-wrapper-env"; + + # Required to use script-based makeWrapper below + strictDeps = true; + + # We don't need/want the unwrapped Prism package + paths = [ ]; + + nativeBuildInputs = old.nativeBuildInputs or [ ] ++ [ + # Ensure the wrapper is script based so it can be sourced + pkgs.makeWrapper + ]; + + # Inspired by https://discourse.nixos.org/t/python-qt-woes/11808/10 + buildCommand = '' + makeQtWrapper ${lib.getExe pkgs.runtimeShellPackage} "$out" + sed -i '/^exec/d' "$out" + ''; + }); in { default = pkgs.mkShell { inputsFrom = [ packages'.prismlauncher-unwrapped ]; - nativeBuildInputs = with pkgs; [ + packages = with pkgs; [ ccache llvm.clang-tools ]; @@ -105,6 +127,9 @@ ]; shellHook = '' + echo "Sourcing ${qt-wrapper-env}" + source ${qt-wrapper-env} + if [ ! -f compile_commands.json ]; then cmake $cmakeFlags -D CMAKE_BUILD_TYPE=Debug ln -s {build/,}compile_commands.json From ddcd61c808329c6fb11f597be8628003a1318121 Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Sun, 30 Mar 2025 19:01:47 -0400 Subject: [PATCH 06/11] refactor(nix): rely more on setup hooks in dev shell Signed-off-by: Seth Flynn (cherry picked from commit de923a07d8a4b7c9f8cd688b9682587c78116e14) --- flake.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index 55d8b0464..339a4026c 100644 --- a/flake.nix +++ b/flake.nix @@ -121,18 +121,18 @@ llvm.clang-tools ]; - cmakeFlags = packages'.prismlauncher-unwrapped.cmakeFlags ++ [ - "-GNinja" - "-Bbuild" - ]; + cmakeBuildType = "Debug"; + cmakeFlags = [ "-GNinja" ] ++ packages'.prismlauncher.cmakeFlags; + dontFixCmake = true; shellHook = '' echo "Sourcing ${qt-wrapper-env}" source ${qt-wrapper-env} if [ ! -f compile_commands.json ]; then - cmake $cmakeFlags -D CMAKE_BUILD_TYPE=Debug - ln -s {build/,}compile_commands.json + cmakeConfigurePhase + cd .. + ln -s "$cmakeBuildDir"/compile_commands.json compile_commands.json fi ''; }; From b02718ee57e625d87b664da33c1903524d9ab4a5 Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Sun, 30 Mar 2025 19:01:47 -0400 Subject: [PATCH 07/11] chore(nix): add nice welcome message to dev shell Signed-off-by: Seth Flynn (cherry picked from commit 38ec7def324891c5062d9b58c1180d44494f91d1) --- flake.nix | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/flake.nix b/flake.nix index 339a4026c..cf5f656d5 100644 --- a/flake.nix +++ b/flake.nix @@ -89,6 +89,24 @@ packages' = self.packages.${system}; + welcomeMessage = '' + Welcome to the Prism Launcher repository! 🌈 + + We just set some things up for you. To get building, you can run: + + ``` + $ cd "$cmakeBuildDir" + $ ninjaBuildPhase + $ ninjaInstallPhase + ``` + + Feel free to ask any questions in our Discord server or Matrix space: + - https://prismlauncher.org/discord + - https://matrix.to/#/#prismlauncher:matrix.org + + And thanks for helping out :) + ''; + # Re-use our package wrapper to wrap our development environment qt-wrapper-env = packages'.prismlauncher.overrideAttrs (old: { name = "qt-wrapper-env"; @@ -134,6 +152,8 @@ cd .. ln -s "$cmakeBuildDir"/compile_commands.json compile_commands.json fi + + echo ${lib.escapeShellArg welcomeMessage} ''; }; } From da9c3591848de09ad92b1878e90dce99e244d5ea Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Sun, 30 Mar 2025 19:01:47 -0400 Subject: [PATCH 08/11] chore(nix): clone git submodules automatically Signed-off-by: Seth Flynn (cherry picked from commit 9b38226f8cb0e2f82bcb017c686fd03520990dd1) --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index cf5f656d5..fd3003bc4 100644 --- a/flake.nix +++ b/flake.nix @@ -147,6 +147,8 @@ echo "Sourcing ${qt-wrapper-env}" source ${qt-wrapper-env} + git submodule update --init --force + if [ ! -f compile_commands.json ]; then cmakeConfigurePhase cd .. From e8bdc72476d499378afcce1fe5ab168e2d479f7c Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Sun, 30 Mar 2025 19:19:30 -0400 Subject: [PATCH 09/11] refactor(nix): use date for version Helps avoid needless rebuilds where only the revision changed. Also better conforms to Nixpkgs' version standards Signed-off-by: Seth Flynn (cherry picked from commit e9cac2e0e37c4531f662545bdc45b72499654642) --- nix/unwrapped.nix | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/nix/unwrapped.nix b/nix/unwrapped.nix index f47051287..2cd127f99 100644 --- a/nix/unwrapped.nix +++ b/nix/unwrapped.nix @@ -24,9 +24,28 @@ assert lib.assertMsg ( gamemodeSupport -> stdenv.hostPlatform.isLinux ) "gamemodeSupport is only available on Linux."; +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 = "prismlauncher-unwrapped"; - version = self.shortRev or self.dirtyShortRev or "unknown"; + version = "10.0-unstable-${date}"; src = lib.fileset.toSource { root = ../.; From b228800de1983a76a3890ccf6940bbf1578a9c57 Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Sun, 30 Mar 2025 19:48:17 -0400 Subject: [PATCH 10/11] chore(gitignore): add more nix-related files Signed-off-by: Seth Flynn (cherry picked from commit de08d7c3644e96a3694f232b53c81f53c40c077a) --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b5523f685..1f4e258a3 100644 --- a/.gitignore +++ b/.gitignore @@ -47,8 +47,12 @@ run/ # Nix/NixOS .direnv/ -.pre-commit-config.yaml +## Used when manually invoking stdenv phases +outputs/ +## Regular artifacts result +result-* +repl-result-* # Flatpak .flatpak-builder From 83f79c93f83c6ccf51bf2eb7bd11632d7572f57b Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Fri, 4 Apr 2025 05:23:47 -0400 Subject: [PATCH 11/11] chore(nix): set stable version Signed-off-by: Seth Flynn --- nix/unwrapped.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/unwrapped.nix b/nix/unwrapped.nix index 2cd127f99..3e91afd89 100644 --- a/nix/unwrapped.nix +++ b/nix/unwrapped.nix @@ -45,7 +45,7 @@ in stdenv.mkDerivation { pname = "prismlauncher-unwrapped"; - version = "10.0-unstable-${date}"; + version = "9.3-unstable-${date}"; src = lib.fileset.toSource { root = ../.;