From 831c38e319870f202d00a607c10b299573080ad6 Mon Sep 17 00:00:00 2001 From: Leah Amelia Chen Date: Fri, 17 May 2024 10:26:58 +0200 Subject: [PATCH 1/2] python3Packages.fastcrc: init at 0.3.2 --- .../python-modules/fastcrc/default.nix | 59 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 2 + 2 files changed, 61 insertions(+) create mode 100644 pkgs/development/python-modules/fastcrc/default.nix diff --git a/pkgs/development/python-modules/fastcrc/default.nix b/pkgs/development/python-modules/fastcrc/default.nix new file mode 100644 index 000000000000..78076c652709 --- /dev/null +++ b/pkgs/development/python-modules/fastcrc/default.nix @@ -0,0 +1,59 @@ +{ + lib, + buildPythonPackage, + pythonOlder, + fetchFromGitHub, + rustPlatform, + pytestCheckHook, + pytest-benchmark, + nix-update-script, +}: +let + pname = "fastcrc"; + version = "0.3.2"; + + src = fetchFromGitHub { + owner = "overcat"; + repo = "fastcrc"; + rev = "refs/tags/v${version}"; + hash = "sha256-yLrv/zqsjgygJAIJtztwxlm4s9o9EBVsCyx1jUXd7hA="; + }; +in +buildPythonPackage { + inherit pname version src; + pyproject = true; + + disabled = pythonOlder "3.7"; + + nativeBuildInputs = with rustPlatform; [ + cargoSetupHook + maturinBuildHook + ]; + + cargoDeps = rustPlatform.fetchCargoTarball { + inherit src; + name = "${pname}-${version}"; + hash = "sha256-wSE7548L+ymNjN9TfygAGY1BrssXOPGXlmE83wV7zb4="; + }; + + pythonImportsCheck = [ "fastcrc" ]; + + nativeCheckInputs = [ + pytestCheckHook + pytest-benchmark + ]; + + # Python source files interfere with testing + preCheck = '' + rm -r fastcrc + ''; + + passthru.updateScript = nix-update-script { }; + + meta = { + description = "Hyper-fast Python module for computing CRC(8, 16, 32, 64) checksum"; + homepage = "https://fastcrc.readthedocs.io/en/latest/"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ pluiedev ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index c09180a5bd4b..57cc2760622d 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -4323,6 +4323,8 @@ self: super: with self; { fastapi-sso = callPackage ../development/python-modules/fastapi-sso { }; + fastcrc = callPackage ../development/python-modules/fastcrc { }; + fast-histogram = callPackage ../development/python-modules/fast-histogram { }; fastavro = callPackage ../development/python-modules/fastavro { }; From c548504474ae3996689ac0c9fd7fe2d90b82744d Mon Sep 17 00:00:00 2001 From: Leah Amelia Chen Date: Fri, 17 May 2024 13:15:29 +0200 Subject: [PATCH 2/2] nzportable: init at 2.0.0-indev+20241012190425 --- pkgs/by-name/nz/nzportable/assets.nix | 44 +++++++ pkgs/by-name/nz/nzportable/fteqw.nix | 176 +++++++++++++++++++++++++ pkgs/by-name/nz/nzportable/package.nix | 84 ++++++++++++ pkgs/by-name/nz/nzportable/quakec.nix | 64 +++++++++ pkgs/by-name/nz/nzportable/update.nix | 41 ++++++ 5 files changed, 409 insertions(+) create mode 100644 pkgs/by-name/nz/nzportable/assets.nix create mode 100644 pkgs/by-name/nz/nzportable/fteqw.nix create mode 100644 pkgs/by-name/nz/nzportable/package.nix create mode 100644 pkgs/by-name/nz/nzportable/quakec.nix create mode 100644 pkgs/by-name/nz/nzportable/update.nix diff --git a/pkgs/by-name/nz/nzportable/assets.nix b/pkgs/by-name/nz/nzportable/assets.nix new file mode 100644 index 000000000000..c002f5c12151 --- /dev/null +++ b/pkgs/by-name/nz/nzportable/assets.nix @@ -0,0 +1,44 @@ +{ + lib, + stdenvNoCC, + fetchFromGitHub, +}: +stdenvNoCC.mkDerivation { + pname = "nzp-assets"; + version = "0-unstable-2024-09-28-13-34-48"; + + src = fetchFromGitHub { + owner = "nzp-team"; + repo = "assets"; + rev = "4a7b1b787061c1c7c17ab3b59a8e0e0f44c9546f"; + hash = "sha256-gCTC/76r0ITIDLIph9uivq0ZJGaPUmlBGizdCUxJrng="; + }; + + outputs = [ + "out" + "pc" + ]; + + # TODO: add more outputs for other ports + installPhase = '' + runHook preInstall + + mkdir -p $out + cp -r common/* $out + + mkdir -p $pc + cp -r pc/* $pc + chmod -R +w $pc/nzp + cp -r $out/* $pc/nzp + + runHook postInstall + ''; + + meta = { + description = "Game asset repository for Nazi Zombies: Portable"; + homepage = "https://github.com/nzp-team/assets"; + license = with lib.licenses; [ cc-by-sa-40 ]; + platforms = lib.platforms.all; + maintainers = with lib.maintainers; [ pluiedev ]; + }; +} diff --git a/pkgs/by-name/nz/nzportable/fteqw.nix b/pkgs/by-name/nz/nzportable/fteqw.nix new file mode 100644 index 000000000000..459873c24b81 --- /dev/null +++ b/pkgs/by-name/nz/nzportable/fteqw.nix @@ -0,0 +1,176 @@ +{ + lib, + stdenv, + fetchFromGitHub, + + cmake, + ninja, + pkg-config, + makeWrapper, + zip, + gettext, + + libpng, + zlib, + gnutls, + libGL, + xorg, + alsa-lib, + libjpeg, + libogg, + libvorbis, + libopus, + dbus, + fontconfig, + SDL2, + bullet, + openexr, + sqlite, + addDriverRunpath, + + enableEGL ? true, + libglvnd, + + enableVulkan ? true, + vulkan-headers, + vulkan-loader, + + enableWayland ? true, + wayland, + libxkbcommon, +}: +stdenv.mkDerivation (finalAttrs: { + pname = "nzp-fteqw"; + version = "0-unstable-2024-09-11-20-07-31"; + + src = fetchFromGitHub { + owner = "nzp-team"; + repo = "fteqw"; + rev = "593345a7f03245fc45580ac252857e5db5105033"; + hash = "sha256-ANDHh4PKh8fAvbBiiW47l1XeGOCes0Sg595+65NFG6w="; + }; + + nativeBuildInputs = [ + cmake + ninja + makeWrapper + pkg-config + zip + gettext + ]; + + buildInputs = + [ + libGL + xorg.libX11 + xorg.libXrandr + xorg.libXcursor + xorg.libXScrnSaver + dbus + fontconfig + libjpeg + libpng + alsa-lib + libogg + libvorbis + libopus + SDL2 + gnutls + zlib + bullet + ] + ++ lib.optional enableEGL libglvnd + ++ lib.optionals enableWayland [ + wayland + libxkbcommon + ] + ++ lib.optional enableVulkan vulkan-headers; + + cmakeFlags = [ + (lib.cmakeFeature "FTE_BUILD_CONFIG" "${finalAttrs.src}/engine/common/config_nzportable.h") + # Disable optional tools - only keep FTEQCC + (lib.cmakeBool "FTE_TOOL_IQM" false) + (lib.cmakeBool "FTE_TOOL_IMAGE" false) + (lib.cmakeBool "FTE_TOOL_QTV" false) + (lib.cmakeBool "FTE_TOOL_MASTER" false) + ]; + + postInstall = '' + mv $out/games $out/bin + ''; + + postFixup = + let + # grep for `Sys_LoadLibrary` for more. + # Some of the deps listed in the source code are actually not active + # due to being either disabled by the nzportable profile (e.g. lua, bz2), + # available in /run/opengl-driver, + # or statically linked (e.g. libpng, libjpeg, zlib, freetype) + # Some of them are also just deprecated by better backend options + # (SDL audio is preferred over ALSA, OpenAL and PulseAudio, for example) + + libs = [ + addDriverRunpath.driverLink + + # gl/gl_vidlinuxglx.c + xorg.libX11 + xorg.libXrandr + xorg.libXxf86vm + xorg.libXxf86dga + xorg.libXi + xorg.libXcursor + libGL + + libvorbis + + sqlite # server/sv_sql.c + + SDL2 # a lot of different files + gnutls # common/net_ssl_gnutls.c + openexr # client/image.c + + (placeholder "out") + ] ++ lib.optional enableWayland wayland ++ lib.optional enableVulkan vulkan-loader; + in + '' + wrapProgram $out/bin/fteqw \ + --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath libs}" + ''; + + meta = { + description = "Nazi Zombies: Portable's fork of Spike's FTEQW engine/client"; + longDescription = '' + This package contains only the FTEQW engine, and none of the assets used in NZ:P. + Please use the `nzportable` package for an out-of-the-box NZ:P experience. + + FTEQW supports several graphics options. + You can specify those graphics option by overriding the FTEQW package, like this: + ```nix + nzp-fteqw.override { + enableVulkan = true; + } + ``` + And in the game, you need to run `setrenderer ` to change the current renderer. + + Supported graphics options are as follows: + - `enableEGL`: Enable the OpenGL ES renderer (`egl`). Enabled by default. + - `enableVulkan`: Enable the Vulkan renderer (`xvk`). Enabled by default. + - `enableWayland`: Enable native Wayland support, instead of using X11. + Adds up to two renderers, based on whether EGL and Vulkan are installed: `wlgl` and `wlvk`. + Seems to be currently broken and currently not enabled by default. + ''; + homepage = "https://github.com/nzp-team/fteqw"; + license = lib.licenses.gpl2Plus; + # See README + platforms = [ + "x86_64-linux" + "i686-linux" + "armv7l-linux" + "aarch64-linux" + "x86_64-windows" + "i686-windows" + ]; + maintainers = with lib.maintainers; [ pluiedev ]; + mainProgram = "fteqw"; + }; +}) diff --git a/pkgs/by-name/nz/nzportable/package.nix b/pkgs/by-name/nz/nzportable/package.nix new file mode 100644 index 000000000000..cb6e4f927324 --- /dev/null +++ b/pkgs/by-name/nz/nzportable/package.nix @@ -0,0 +1,84 @@ +{ + lib, + callPackage, + writeShellApplication, +}: +let + assets = callPackage ./assets.nix { }; + quakec = callPackage ./quakec.nix { }; + fteqw = callPackage ./fteqw.nix { }; + + # We use the youngest version of all of the dependencies as the version number. + # This is similar to what upstream uses, except ours is a bit more accurate + # since we don't rely on a CI to run at an arbitrary time. + dateString = + lib.pipe + [ + assets + fteqw + quakec + ] + [ + # Find the youngest (most recently updated) version + (lib.foldl' (acc: p: if lib.versionOlder acc p.version then p.version else acc) "") + (lib.splitString "-") + (lib.sublist 2 6) # drop the first two segments (0 and unstable) and only keep the date + lib.concatStrings + ]; + + version = "2.0.0-indev+${dateString}"; +in +writeShellApplication { + name = "nzportable"; + + text = '' + runDir=''${XDG_DATA_HOME:-$HOME/.local/share}/nzportable + data=${assets.pc} + + relinkGameFiles() { + mkdir -p "$runDir"/nzp + + # Remove existing links + find "$runDir" -type l -exec rm {} + + + # Link game files + ln -s $data/default.fmf "$runDir" + ln -st "$runDir"/nzp $data/nzp/* ${quakec.fte}/* + + # Write current version + echo "${version}" > "$runDir"/nzp/version.txt + } + + if [[ ! -d $runDir ]]; then + echo "Game directory $runDir not found. Assuming first launch" + echo "Linking game files" + relinkGameFiles + else + currentVersion=$(<"$runDir"/nzp/version.txt) + if [[ "${version}" != "$currentVersion" ]]; then + echo "Version mismatch! (saved version $currentVersion != current version ${version})" + echo "Relinking game files" + relinkGameFiles + fi + fi + + exec ${lib.getExe fteqw} -basedir "$runDir" "$@" + ''; + + derivationArgs = { + inherit version; + passthru = { + updateScript = callPackage ./update.nix { }; + inherit assets quakec fteqw; + }; + }; + + meta = { + inherit (fteqw.meta) platforms; + description = "Call of Duty: Zombies demake, powered by various Quake sourceports (PC version)"; + homepage = "https://docs.nzp.gay"; + license = lib.licenses.gpl2Plus; + maintainers = with lib.maintainers; [ pluiedev ]; + mainProgram = "nzportable"; + }; +} diff --git a/pkgs/by-name/nz/nzportable/quakec.nix b/pkgs/by-name/nz/nzportable/quakec.nix new file mode 100644 index 000000000000..32fb863d7508 --- /dev/null +++ b/pkgs/by-name/nz/nzportable/quakec.nix @@ -0,0 +1,64 @@ +{ + lib, + stdenvNoCC, + fetchFromGitHub, + python3, + nzportable, +}: +stdenvNoCC.mkDerivation { + pname = "nzp-quakec"; + version = "0-unstable-2024-10-12-12-03-59"; + + src = fetchFromGitHub { + owner = "nzp-team"; + repo = "quakec"; + rev = "01e95c4dab91ce0e8b7387d2726d9ee307792ae7"; + hash = "sha256-h4llx3tzeoI1aHLokM7NqkZJWuo6rcrmWfb0pDQL+zM="; + }; + + outputs = [ + "out" + "fte" + ]; + + nativeBuildInputs = [ python3 ]; + + buildInputs = with python3.pkgs; [ + colorama + fastcrc + pandas + nzportable.fteqw + ]; + + buildPhase = '' + runHook preBuild + + python3 bin/qc_hash_generator.py -i tools/asset_conversion_table.csv -o source/server/hash_table.qc + + mkdir -p build/{fte,standard} + + fteqcc -srcfile progs/csqc.src + fteqcc -O3 -DFTE -srcfile progs/ssqc.src + fteqcc -O3 -srcfile progs/ssqc.src + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out $fte + cp -r build/standard/* $out + cp -r build/fte/* $fte + + runHook postInstall + ''; + + meta = { + description = "QuakeC repository for Nazi Zombies: Portable"; + homepage = "https://github.com/nzp-team/quakec"; + license = lib.licenses.gpl2Plus; + platforms = with lib.platforms; linux ++ darwin; + maintainers = with lib.maintainers; [ pluiedev ]; + }; +} diff --git a/pkgs/by-name/nz/nzportable/update.nix b/pkgs/by-name/nz/nzportable/update.nix new file mode 100644 index 000000000000..03c4a1cd1e5a --- /dev/null +++ b/pkgs/by-name/nz/nzportable/update.nix @@ -0,0 +1,41 @@ +{ + lib, + writeShellApplication, + jq, + curl, + nix-prefetch-git, + common-updater-scripts, +}: + +lib.getExe (writeShellApplication { + name = "nzp-updater"; + runtimeInputs = [ + jq + curl + nix-prefetch-git + common-updater-scripts + ]; + text = '' + youngest=0 + update() { + repo=$1 + tag=$2 + + prefetch=$(nix-prefetch-git "https://github.com/nzp-team/$repo" --rev "$tag") + + timestamp=$(echo "$prefetch" | jq -r '.date | strptime("%Y-%m-%dT%H:%M:%S%z") | mktime | strftime("%Y-%m-%d-%H-%M-%S")') + rev=$(echo "$prefetch" | jq -r ".rev") + hash=$(echo "$prefetch" | jq -r ".hash") + + if [[ $youngest -lt $timestamp ]]; then + youngest=$timestamp + fi + + update-source-version "$UPDATE_NIX_ATTR_PATH.$repo" "0-unstable-$timestamp" "$hash" --rev="$rev" + } + + update fteqw bleeding-edge + update assets newest + update quakec bleeding-edge + ''; +})