aboutsummaryrefslogtreecommitdiff
path: root/srcds-pkgs/build-sm-plugin.nix
diff options
context:
space:
mode:
authoryuuko <yuuko@partyvan.io>2024-08-29 21:51:04 -0700
committeryuuko <yuuko@partyvan.io>2024-08-29 21:51:04 -0700
commit56449e59d7aabd1c06fb67a51a1e129b55cb9270 (patch)
tree19f3faf805e9b6461a5940d1a050d13e5271ef55 /srcds-pkgs/build-sm-plugin.nix
break out of system config
Diffstat (limited to 'srcds-pkgs/build-sm-plugin.nix')
-rw-r--r--srcds-pkgs/build-sm-plugin.nix71
1 files changed, 71 insertions, 0 deletions
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 ];
+})