nix/nix/sourcemod/sourcemod.nix

92 lines
3 KiB
Nix

{
stdenv,
fetchFromGitHub,
ambuild,
metamod-source,
symlinkJoin,
lib,
writeShellScriptBin,
zlib,
writeScript,
}: sdks: let
inherit (builtins) concatStringsSep attrNames attrValues;
inherit (lib) optionals;
combinedSdks = symlinkJoin {
name = "hl2sdk-${concatStringsSep "-" (attrNames sdks)}";
paths = attrValues sdks;
};
ambuildArchs = {
"x86_64-linux" = "x86_64";
"i686-linux" = "x86";
};
ambuildArch = ambuildArchs.${stdenv.system};
sdkNames = concatStringsSep "," (attrNames sdks);
# ambuild doesn't allow configuring a target prefix for "ar"
arWrapper = writeShellScriptBin "ar" "exec -a $0 ${stdenv.cc.targetPrefix}ar $@";
in
stdenv.mkDerivation (finalAttrs: {
pname = "sourcemod";
version = "1.12.0.7239";
src = fetchFromGitHub {
owner = "alliedmodders";
repo = finalAttrs.pname;
rev = "b951843d42f7b9204615c14885468ea131a24002";
sha256 = "sha256-aulM6fzXcmQf0xztWDRyxbH02mTGJKPMqpUMUSeNbaM=";
fetchSubmodules = true;
};
NIX_CFLAGS_COMPILE =
"-Wno-error -Wno-error=format-truncation -Wno-error=ignored-attributes -Wno-error=reorder -Wno-error=sign-compare "
+ "-Wno-error=stringop-truncation -Wno-error=dangling-pointer -Wno-error=template-id-cdtor -Wno-error=format-security "
+ "-Wno-error=deprecated-declarations -Wno-error=stringop-overread";
nativeBuildInputs =
[
ambuild
]
++ optionals (stdenv.cc.targetPrefix != "") [arWrapper];
buildInputs = [
zlib
];
configurePhase = ''
mkdir build
cd build
python ../configure.py --targets ${ambuildArch} --enable-optimize --sdks=${sdkNames} \
--no-mysql --disable-auto-versioning --mms-path=${metamod-source.src} --hl2sdk-root=${combinedSdks}
'';
buildPhase = ''
ambuild
'';
installPhase = ''
mkdir $out
mv package $out/share
'';
passthru.updateScript = writeScript "update-sourcemod" ''
#!/usr/bin/env nix-shell
#!nix-shell -i nu -p nurl common-updater-scripts
let html = http get https://www.sourcemod.net/downloads.php?branch=stable
let branch = $html | query web --query h3 | first | first | parse --regex "from (?P<branch>[0-9.]+) Branch" | get branch | first
let build = $html | query web --as-table [Build] | get 1 | get Build | first
let newRev = $html | query web --query 'td a[href^="https://github.com/alliedmodders/sourcemod/tree/"]' --attribute ['href'] | first | get href | split words | last
let oldHash = nix eval --raw .#sourcemod.src.hash
let oldRev = nix eval --raw .#sourcemod.src.rev
let oldVersion = nix eval --raw .#sourcemod.version
let newHash = nurl https://github.com/alliedmodders/sourcemod $newRev --submodules --hash
let newVersion = $"($branch).0.($build)"
let nix = open nix/sourcemod/sourcemod.nix |
str replace $oldHash $newHash |
str replace $oldVersion $newVersion |
str replace $oldRev $newRev
$nix | save -f nix/sourcemod/sourcemod.nix
'';
})