From 56449e59d7aabd1c06fb67a51a1e129b55cb9270 Mon Sep 17 00:00:00 2001 From: yuuko Date: Thu, 29 Aug 2024 21:51:04 -0700 Subject: break out of system config --- srcds-pkgs/ambuild.nix | 23 ++++++ srcds-pkgs/bad/libfinite.nix | 20 ++++++ srcds-pkgs/bad/mysql_5_5.nix | 14 ++++ srcds-pkgs/build-sm-plugin.nix | 71 +++++++++++++++++++ srcds-pkgs/default.nix | 55 +++++++++++++++ .../0001-emit-json-in-.DepotDownload.patch | 51 ++++++++++++++ ...2-ProtoManifest-sort-files-in-constructor.patch | 24 +++++++ srcds-pkgs/depotdownloader-json/default.nix | 10 +++ srcds-pkgs/extensions/SM-Memory.nix | 51 ++++++++++++++ srcds-pkgs/extensions/SM-neocurl-ext.nix | 43 ++++++++++++ srcds-pkgs/fetchdepotcache.nix | 27 +++++++ srcds-pkgs/fetchdepotfile.nix | 46 ++++++++++++ srcds-pkgs/hl2sdk-2013.nix | 9 +++ srcds-pkgs/metamod-source.nix | 66 +++++++++++++++++ srcds-pkgs/mkdepot.nix | 19 +++++ srcds-pkgs/plugins/Chat-Logger-Redux.nix | 19 +++++ srcds-pkgs/plugins/Open-Fortress-Tools.nix | 15 ++++ srcds-pkgs/plugins/SteamTools.nix | 21 ++++++ srcds-pkgs/plugins/SteamWorks.nix | 19 +++++ srcds-pkgs/plugins/Updater.nix | 28 ++++++++ srcds-pkgs/plugins/ftz_cheats.nix | 14 ++++ srcds-pkgs/plugins/morecolors.nix | 20 ++++++ srcds-pkgs/plugins/nativevotes-updated.nix | 16 +++++ srcds-pkgs/plugins/openfrags.nix | 16 +++++ srcds-pkgs/plugins/smlib.nix | 22 ++++++ srcds-pkgs/plugins/socket.nix | 27 +++++++ srcds-pkgs/plugins/yuuko_votes.nix | 13 ++++ srcds-pkgs/sourcemod/default.nix | 82 ++++++++++++++++++++++ srcds-pkgs/sourcemod/setup-hook.sh | 16 +++++ 29 files changed, 857 insertions(+) create mode 100644 srcds-pkgs/ambuild.nix create mode 100644 srcds-pkgs/bad/libfinite.nix create mode 100644 srcds-pkgs/bad/mysql_5_5.nix create mode 100644 srcds-pkgs/build-sm-plugin.nix create mode 100644 srcds-pkgs/default.nix create mode 100644 srcds-pkgs/depotdownloader-json/0001-emit-json-in-.DepotDownload.patch create mode 100644 srcds-pkgs/depotdownloader-json/0002-ProtoManifest-sort-files-in-constructor.patch create mode 100644 srcds-pkgs/depotdownloader-json/default.nix create mode 100644 srcds-pkgs/extensions/SM-Memory.nix create mode 100644 srcds-pkgs/extensions/SM-neocurl-ext.nix create mode 100644 srcds-pkgs/fetchdepotcache.nix create mode 100644 srcds-pkgs/fetchdepotfile.nix create mode 100644 srcds-pkgs/hl2sdk-2013.nix create mode 100644 srcds-pkgs/metamod-source.nix create mode 100644 srcds-pkgs/mkdepot.nix create mode 100644 srcds-pkgs/plugins/Chat-Logger-Redux.nix create mode 100644 srcds-pkgs/plugins/Open-Fortress-Tools.nix create mode 100644 srcds-pkgs/plugins/SteamTools.nix create mode 100644 srcds-pkgs/plugins/SteamWorks.nix create mode 100644 srcds-pkgs/plugins/Updater.nix create mode 100644 srcds-pkgs/plugins/ftz_cheats.nix create mode 100644 srcds-pkgs/plugins/morecolors.nix create mode 100644 srcds-pkgs/plugins/nativevotes-updated.nix create mode 100644 srcds-pkgs/plugins/openfrags.nix create mode 100644 srcds-pkgs/plugins/smlib.nix create mode 100644 srcds-pkgs/plugins/socket.nix create mode 100644 srcds-pkgs/plugins/yuuko_votes.nix create mode 100644 srcds-pkgs/sourcemod/default.nix create mode 100644 srcds-pkgs/sourcemod/setup-hook.sh (limited to 'srcds-pkgs') diff --git a/srcds-pkgs/ambuild.nix b/srcds-pkgs/ambuild.nix new file mode 100644 index 0000000..5621f49 --- /dev/null +++ b/srcds-pkgs/ambuild.nix @@ -0,0 +1,23 @@ +{ lib, buildPythonPackage, fetchFromGitHub }: +let + owner = "alliedmodders"; +in buildPythonPackage rec { + pname = "ambuild"; + version = "2024-07-07"; + + src = fetchFromGitHub { + inherit owner; + repo = pname; + rev = "551dd3f630f90377cbe536fbaf12e0b6bca91253"; + sha256 = "1xfjxs3ajrrz66pdspwrnr5faifk1r3i5nha8vmz510z07h5g6g3"; + }; + + # doCheck = false; + + meta = with lib; { + description = "Lightweight build system designed for performance and accuracy"; + homepage = "https://github.com/${owner}/${pname}"; + platforms = platforms.unix; + license = licenses.bsd3; + }; +} diff --git a/srcds-pkgs/bad/libfinite.nix b/srcds-pkgs/bad/libfinite.nix new file mode 100644 index 0000000..300bd18 --- /dev/null +++ b/srcds-pkgs/bad/libfinite.nix @@ -0,0 +1,20 @@ +# https://sourceware.org/git/?p=glibc.git;a=commit;h=7bdb921d +{ runCommandWith, multiStdenv, writeText }: +runCommandWith { + stdenv = multiStdenv; + name = "libfinite.a"; +} '' + cc -o finite.o -m32 -c ${writeText "finite.c" '' + #include + /* metamod */ + double __pow_finite(double x, double y) { return pow(x, y); } + /* sourcemod */ + float __acosf_finite(float x) { return acosf(x); }; + double __acos_finite(double x) { return acos(x); }; + double __asin_finite(double x) { return asin(x); }; + float __atan2f_finite(double y, double x) { return atan2f(y, x); } + double __atan2_finite(double y, double x) { return atan2(y, x); } + double __log_finite(double x) { return log(x); } + ''} + ar rcs $out finite.o +'' diff --git a/srcds-pkgs/bad/mysql_5_5.nix b/srcds-pkgs/bad/mysql_5_5.nix new file mode 100644 index 0000000..bd7534c --- /dev/null +++ b/srcds-pkgs/bad/mysql_5_5.nix @@ -0,0 +1,14 @@ +# TODO: find out if sourcemod is lying about needing to build against 5.5 +{ lib, stdenv, fetchurl, ncurses, cmake }: +stdenv.mkDerivation rec { + pname = "mysql"; + version = "5.5.62"; + + src = fetchurl { + url = "https://downloads.mysql.com/archives/get/p/23/file/mysql-${version}.tar.gz"; + hash = "sha256-seeFO8HwSqv2dx4K2UfzWsjSN/SzXQcG0QlclSb/mdc="; + }; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ ncurses ]; +} diff --git a/srcds-pkgs/build-sm-plugin.nix b/srcds-pkgs/build-sm-plugin.nix new file mode 100644 index 0000000..d55338d --- /dev/null +++ b/srcds-pkgs/build-sm-plugin.nix @@ -0,0 +1,71 @@ +/* there is a lot of hideous directory-shuffling bureaucracy here. it + * encompasses all that has been found necessary out in the wild. sourcemod + * plugins following a sane standard project structure is a fairly recent + * development. + */ +{ lib, stdenvNoCC, sourcemod }: +{ scriptingPath ? "scripting" +, includePath ? "scripting/include" +, pluginsPath ? "plugins" +, translationsPath ? "translations" +, gamedataPath ? "gamedata" +, removePrebuilt ? true +, nativeBuildInputs ? [] +, ... +}@args: +let + inherit (lib) hasSuffix; +in +assert !hasSuffix "/" scriptingPath; +assert !hasSuffix "/" includePath; +assert !hasSuffix "/" pluginsPath; +assert !hasSuffix "/" translationsPath; +assert !hasSuffix "/" gamedataPath; +stdenvNoCC.mkDerivation ({ + inherit + scriptingPath includePath pluginsPath translationsPath gamedataPath + removePrebuilt; + configurePhase = '' + runHook preConfigure + source <(for d in scripting include plugins translations gamedata; do + echo "''${d}Path=$PWD/"\$"''${d}Path" + done) + cd /build + for p in scripting plugins translations gamedata; do + path="$(eval echo \$"''${p}Path")" + [ -d "$path" ] && cp -rT "$path" ./"$p" + done + case "$includePath" in + "$scriptingPath/include") :;; + "$scriptingPath"/*) echo TODO; exit 1;; + *) cp -r "$includePath" ./scripting/include;; + esac + [ -n "''${removePrebuilt:-}" ] && rm -f plugins/*.smx; + mkdir -p scripting/include plugins/disabled translations gamedata + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + cd /build/scripting + [ -d ./include ] && SPCOMPFLAGS="$SPCOMPFLAGS -i ./include" + for plug in *.sp; do + spcomp -o "../plugins/disabled/''${plug%.sp}.smx" "$plug" + done + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + cd /build + find . -type d -empty -delete + odir=$out/share/addons/sourcemod + mkdir -p $odir + for d in scripting plugins translation gamedata; do + [ -d $d ] && cp -r $d $odir/$d + done + runHook postInstall + ''; +} // args // { + nativeBuildInputs = nativeBuildInputs ++ [ sourcemod ]; +}) diff --git a/srcds-pkgs/default.nix b/srcds-pkgs/default.nix new file mode 100644 index 0000000..1b8294c --- /dev/null +++ b/srcds-pkgs/default.nix @@ -0,0 +1,55 @@ +let f = self: with self; { + inherit (self) callPackage; + + libfinite = callPackage ./bad/libfinite.nix {}; + mysql_5_5 = pkgs.pkgsi686Linux.callPackage ./bad/mysql_5_5.nix {}; + + ambuild = callPackage ./ambuild.nix { + inherit (pkgs.python3Packages) buildPythonPackage; + }; + + hl2sdk-2013 = callPackage ./hl2sdk-2013.nix {}; + + metamod-source = callPackage ./metamod-source.nix { + hl2sdk = hl2sdk-2013; + }; + sourcemod = callPackage ./sourcemod { + hl2sdk = hl2sdk-2013; + }; + + buildSMPlugin = callPackage ./build-sm-plugin.nix {}; + # TODO: see if it even makes sense to abstract this hard + # buildSMExtension = callPackage ./build-sm-extension.nix {}; + + depotdownloader-json = callPackage ./depotdownloader-json {}; + + fetchDepotCache = callPackage ./fetchdepotcache.nix { + depotdownloader = depotdownloader-json; + }; + fetchDepotFile = callPackage ./fetchdepotfile.nix { + depotdownloader = depotdownloader-json; + }; + mkDepot = callPackage ./mkdepot.nix {}; + + SM-Memory = callPackage ./extensions/SM-Memory.nix {}; + SM-neocurl-ext = callPackage ./extensions/SM-neocurl-ext.nix {}; + + Chat-Logger-Redux = callPackage ./plugins/Chat-Logger-Redux.nix {}; + Open-Fortress-Tools = callPackage ./plugins/Open-Fortress-Tools.nix {}; + SteamTools = callPackage ./plugins/SteamTools.nix {}; + SteamWorks = callPackage ./plugins/SteamWorks.nix {}; + Updater = callPackage ./plugins/Updater.nix {}; + ftz_cheats = callPackage ./plugins/ftz_cheats.nix {}; + morecolors = callPackage ./plugins/morecolors.nix {}; + nativevotes-updated = callPackage ./plugins/nativevotes-updated.nix {}; + openfrags = callPackage ./plugins/openfrags.nix {}; + smlib = callPackage ./plugins/smlib.nix {}; + socket = callPackage ./plugins/socket.nix {}; + yuuko_votes = callPackage ./plugins/yuuko_votes.nix {}; +}; in +{ lib +, newScope +, recurseIntoAttrs +, pkgs +}: +recurseIntoAttrs (lib.makeScope newScope (self: f self // { inherit pkgs; })) diff --git a/srcds-pkgs/depotdownloader-json/0001-emit-json-in-.DepotDownload.patch b/srcds-pkgs/depotdownloader-json/0001-emit-json-in-.DepotDownload.patch new file mode 100644 index 0000000..6a58ac6 --- /dev/null +++ b/srcds-pkgs/depotdownloader-json/0001-emit-json-in-.DepotDownload.patch @@ -0,0 +1,51 @@ +From 5ca2011ef9c6463c6e5953101792b663b6546373 Mon Sep 17 00:00:00 2001 +From: yuuko +Date: Fri, 31 Mar 2023 16:03:32 -0700 +Subject: [PATCH] emit json in .DepotDownload + +--- + DepotDownloader/ContentDownloader.cs | 1 + + DepotDownloader/ProtoManifest.cs | 8 ++++++++ + 2 files changed, 9 insertions(+) + +diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs +index 7cee83f7..3bf79aa5 100644 +--- a/DepotDownloader/ContentDownloader.cs ++++ b/DepotDownloader/ContentDownloader.cs +@@ -929,6 +929,7 @@ namespace DepotDownloader + + newProtoManifest = new ProtoManifest(depotManifest, depot.manifestId); + newProtoManifest.SaveToFile(newManifestFileName, out checksum); ++ newProtoManifest.SaveToJSON(newManifestFileName.Replace(".bin", ".json")); + File.WriteAllBytes(newManifestFileName + ".sha", checksum); + + Console.WriteLine(" Done!"); +diff --git a/DepotDownloader/ProtoManifest.cs b/DepotDownloader/ProtoManifest.cs +index 70389a05..c5e12cfc 100644 +--- a/DepotDownloader/ProtoManifest.cs ++++ b/DepotDownloader/ProtoManifest.cs +@@ -2,6 +2,8 @@ + using System.Collections.Generic; + using System.IO; + using System.IO.Compression; ++using System.Text; ++using System.Text.Json; + using ProtoBuf; + using SteamKit2; + +@@ -142,6 +144,12 @@ namespace DepotDownloader + } + } + ++ public void SaveToJSON(string filename) ++ { ++ var jsonBytes = new UTF8Encoding(true).GetBytes(JsonSerializer.Serialize(this)); ++ File.Open(filename, FileMode.Create).Write(jsonBytes, 0, jsonBytes.Length); ++ } ++ + public void SaveToFile(string filename, out byte[] checksum) + { + using (var ms = new MemoryStream()) +-- +2.38.4 + diff --git a/srcds-pkgs/depotdownloader-json/0002-ProtoManifest-sort-files-in-constructor.patch b/srcds-pkgs/depotdownloader-json/0002-ProtoManifest-sort-files-in-constructor.patch new file mode 100644 index 0000000..ac4fe97 --- /dev/null +++ b/srcds-pkgs/depotdownloader-json/0002-ProtoManifest-sort-files-in-constructor.patch @@ -0,0 +1,24 @@ +From 7c067e609efabd54039905dc35edf91afb6c5dad Mon Sep 17 00:00:00 2001 +From: yuuko +Date: Wed, 1 Nov 2023 06:46:57 -0700 +Subject: [PATCH] ProtoManifest: sort files in constructor + +--- + DepotDownloader/ProtoManifest.cs | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/DepotDownloader/ProtoManifest.cs b/DepotDownloader/ProtoManifest.cs +index c5e12cfc..5f66595c 100644 +--- a/DepotDownloader/ProtoManifest.cs ++++ b/DepotDownloader/ProtoManifest.cs +@@ -21,6 +21,7 @@ namespace DepotDownloader + public ProtoManifest(DepotManifest sourceManifest, ulong id) : this() + { + sourceManifest.Files.ForEach(f => Files.Add(new FileData(f))); ++ Files.Sort((f1,f2) => f1.FileName.CompareTo(f2.FileName)); + ID = id; + CreationTime = sourceManifest.CreationTime; + } +-- +2.42.0 + diff --git a/srcds-pkgs/depotdownloader-json/default.nix b/srcds-pkgs/depotdownloader-json/default.nix new file mode 100644 index 0000000..c09422d --- /dev/null +++ b/srcds-pkgs/depotdownloader-json/default.nix @@ -0,0 +1,10 @@ +{ depotdownloader }: +depotdownloader.overrideAttrs({ patches ? [], version, ... }: { + patches = assert builtins.elem version [ "2.4.7" "2.5.0" ]; patches ++ [ + # with this, nix has access to the hashes in the manifest + ./0001-emit-json-in-.DepotDownload.patch + # the manifest can arrive out of order across requests to the same build! + # luckily that singular reproducibility snag is patched in 1 line. + ./0002-ProtoManifest-sort-files-in-constructor.patch + ]; +}) diff --git a/srcds-pkgs/extensions/SM-Memory.nix b/srcds-pkgs/extensions/SM-Memory.nix new file mode 100644 index 0000000..5d1761a --- /dev/null +++ b/srcds-pkgs/extensions/SM-Memory.nix @@ -0,0 +1,51 @@ +{ lib, multiStdenv, fetchFromGitHub +, metamod-source, sourcemod, ambuild +, ed +}: +multiStdenv.mkDerivation rec { + pname = "SM-Memory"; + version = "1.5.1"; + + src = fetchFromGitHub { + owner = "Scags"; + repo = pname; + rev = "V${version}"; + sha256 = "031nbx18hhqgnryzy00rv5bc8v1k7fbkb3677ndm7nkif13p12aa"; + }; + + nativeBuildInputs = [ ambuild sourcemod ed ]; + + patchPhase = '' + pushd pawn/sourcemod/scripting + substituteInPlace memtest_{func,vec}.sp --replace smmem_ smmem/ + ed memtest.sp < + . + w + EOF + popd + ''; + + configurePhase = '' + cd build + python ../configure.py \ + --sm-path ${sourcemod.src} \ + --mms-path ${metamod-source.src} + ''; + + buildPhase = '' + ambuild + pushd package/addons/sourcemod/scripting + mkdir -p ../plugins/disabled + for i in *.sp; do + spcomp -i include $i -o ../plugins/disabled/''${i%.sp}.smx + done + popd + ''; + + installPhase = '' + mkdir $out + mv package $out/share + ''; +} diff --git a/srcds-pkgs/extensions/SM-neocurl-ext.nix b/srcds-pkgs/extensions/SM-neocurl-ext.nix new file mode 100644 index 0000000..8ac2e02 --- /dev/null +++ b/srcds-pkgs/extensions/SM-neocurl-ext.nix @@ -0,0 +1,43 @@ +# pkgsi686Linux.pkgsStatic.callPackage +{ lib, multiStdenv, fetchgit, ed +, metamod-source, sourcemod, ambuild, pkg-config, pkg-config-unwrapped +, pkgsi686Linux +}: +multiStdenv.mkDerivation rec { + pname = "SM-neocurl-ext"; + version = "2.0.1"; + + src = fetchgit { + url = "https://git.partyvan.io/${pname}"; + rev = "0f0f543d79966fc938b3205e5273820e4c2edc56"; + hash = "sha256-zRZddNWc6rl4E/StpTuwtMoL0GVuPRAbcihJ0ViKddo="; + }; + + patchPhase = '' + ed AMBuilder < .git/HEAD + ed support/buildbot/generate_headers.py </a #include ' \ + scripting/include/smlib/entities.inc + ''; + + # technically unnecessary as buildPhase simply won't find anything to build + dontBuild = true; +} diff --git a/srcds-pkgs/plugins/socket.nix b/srcds-pkgs/plugins/socket.nix new file mode 100644 index 0000000..5a7cdc2 --- /dev/null +++ b/srcds-pkgs/plugins/socket.nix @@ -0,0 +1,27 @@ +{ buildSMPlugin, fetchFromGitHub, runCommand }: +let + src' = fetchFromGitHub { + owner = "nefarius"; + repo = "sm-ext-socket"; + rev = "ed6bf7a12bd3f801610592301e12062b367fa27b"; + hash = "sha256-M13Nt58tlXXBO1fB2Y3vQLyD4Wlzrwd6mHWSf5JTUwY="; + }; + /* + socket.src = fetchzip { + url = "http://forums.alliedmods.net/attachment.php?attachmentid=83286"; + extension = "zip"; + stripRoot = false; + hash = "sha256-EDCEyzSynz8Uotgx6xVmEiGgXf1FBtOzW1YNfsOad+U="; + }; + */ +in +buildSMPlugin rec { + pname = "socket"; + version = "2018-11-14"; + + src = runCommand "source" {} '' + odir=$out/scripting/include + mkdir -p $odir + cp ${src'}/socket.inc $odir/ + ''; +} diff --git a/srcds-pkgs/plugins/yuuko_votes.nix b/srcds-pkgs/plugins/yuuko_votes.nix new file mode 100644 index 0000000..fb11fad --- /dev/null +++ b/srcds-pkgs/plugins/yuuko_votes.nix @@ -0,0 +1,13 @@ +{ lib, buildSMPlugin, fetchgit, SM-Memory }: +buildSMPlugin rec { + pname = "yuuko_votes"; + version = "2024-08-12"; + + src = fetchgit { + url = "https://git.partyvan.io/yuuko_votes"; + rev = "acafa384e1dfec7d877bc4fcac0dc78e8f9429db"; + hash = "sha256-PNCl9oM2j0CSiJp6jt0Cn9gGwGsbwmZ55xt/m05Tmzc="; + }; + + buildInputs = [ SM-Memory ]; +} diff --git a/srcds-pkgs/sourcemod/default.nix b/srcds-pkgs/sourcemod/default.nix new file mode 100644 index 0000000..90c31f9 --- /dev/null +++ b/srcds-pkgs/sourcemod/default.nix @@ -0,0 +1,82 @@ +{ lib, multiStdenv, pkgsi686Linux +, writeShellScript +, fetchFromGitHub, ed +, hl2sdk, ambuild, metamod-source, libfinite +, mysql_5_5 +}: let + inherit (pkgsi686Linux) zlib; + owner = "alliedmodders"; + buildno = "6968"; +in multiStdenv.mkDerivation rec { + pname = "sourcemod"; + version = "1.11_${buildno}"; + + src = fetchFromGitHub rec { + inherit owner; + repo = pname; + rev = "13510eab809a98b6a62354fc9848641"; + fetchSubmodules = true; + hash = "sha256-leV0Q7g5bnJljzQxv3z6t5p/1d9TxILPvIuSYuq8LmE="; + }; + + nativeBuildInputs = [ ambuild ed ]; + buildInputs = [ zlib mysql_5_5 ]; + + hardeningDisable = [ "all" ]; + + CXXFLAGS="-Wno-error=sign-compare -Wno-error=ignored-attributes"; + + postPatch = '' + mkdir .git + echo "ref: refs/heads/main" > .git/HEAD + ed tools/buildbot/generate_headers.py <