nix/nix/srcds/default.nix

110 lines
2.9 KiB
Nix

{
lib,
stdenvNoCC,
fetchSteam,
depotdownloader,
writeScript,
symlinkJoin,
autoPatchelfHook,
libgcc,
curlWithGnuTls,
steamworks-sdk-redist,
system,
}: let
inherit (builtins) fromJSON readFile map toString elem head replaceStrings;
depotInputs = fromJSON (readFile ./depots.json);
fetchSupported = elem system depotdownloader.meta.platforms;
fetcher = input:
if fetchSupported
then
fetchSteam {
name = "steam-depot-${toString input.app_id}-${toString input.depot_id}";
appId = input.app_id;
depotId = input.depot_id;
manifestId = input.manifest;
fileList = input.file_list or [];
hash = input.hash;
}
else
stdenvNoCC.mkDerivation {
name = "steam-depot-${toString input.app_id}-${toString input.depot_id}";
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = input.hash;
preferLocalBuild = true;
allowSubstitutes = false;
builder = writeScript "restrict-message" ''
source ${stdenvNoCC}/setup
cat <<_EOF_
$out
fetchSteam is not supported on your platform
_EOF_
exit 1
'';
};
allDepots = map fetcher depotInputs;
src = symlinkJoin {
name = "srcds-tf2-src";
paths = allDepots;
};
timeToVersion = replaceStrings ["T" ":" "Z"] ["-" "-" ""];
time = (head depotInputs).date;
curlCompat = curlWithGnuTls.overrideAttrs (
final: prev: {
patches = (prev.patches or []) ++ [./curl-symbol-downgrade.patch];
}
);
mainProgram =
if system == "x86_64-linux"
then "srcds_run_64"
else "srcds_run";
in
stdenvNoCC.mkDerivation {
pname = "srcds-tf2";
version = timeToVersion time;
inherit src;
# Skip phases that don't apply to prebuilt binaries.
dontBuild = true;
dontConfigure = true;
nativeBuildInputs = [autoPatchelfHook];
buildInputs = [libgcc curlCompat];
installPhase = ''
runHook preInstall
cp -rL . $out
chmod -R +w $out
# the steamclient.so included in the depot is 32bit so it wont work
cp ${steamworks-sdk-redist}/lib/steamclient.so $out/bin/steamclient.so
chmod -R +w $out/bin/steamclient.so
echo 440 > $out/steam_appid.txt
mkdir -p $out/bin
echo "#! /bin/sh" > $out/bin/${mainProgram}
echo "exec $out/${mainProgram} "'$@' >> $out/bin/${mainProgram}
chmod +x $out/bin/${mainProgram}
runHook postInstall
'';
meta = with lib; {
inherit mainProgram;
description = "TF2 dedicated server";
homepage = "https://steamdb.info/app/440/";
changelog = "https://store.steampowered.com/news/app/440?updates=true";
sourceProvenance = with sourceTypes; [
binaryNativeCode
];
license = licenses.unfree;
platforms = ["x86_64-linux" "i686-linux"];
};
}