add withConfig for srcds

This commit is contained in:
Robin Appelman 2026-07-09 16:50:06 +02:00
commit 1d9037fc6c
3 changed files with 50 additions and 12 deletions

View file

@ -45,16 +45,23 @@
steam-depots = pkgs.steam-depots; steam-depots = pkgs.steam-depots;
}; };
packages = inheritPkgs [ packages =
"ambuild" inheritPkgs [
"sourcepawn" "ambuild"
"sourcemod" "sourcepawn"
"sourcemod-includes" "sourcemod"
"sourcemod-include-curl" "sourcemod-includes"
"sourcemod-include-library" "sourcemod-include-curl"
"sourcemod-include-steamworks" "sourcemod-include-library"
"srcds-tf2" "sourcemod-include-steamworks"
]; "srcds-tf2"
]
// {
test = pkgs:
pkgs.srcds-tf2.withConfig {
hostname = "Spire Server";
};
};
checks = { checks = {
buildTestScript = {pkgs, ...}: buildTestScript = {pkgs, ...}:

11
nix/srcds/cfg.nix Normal file
View file

@ -0,0 +1,11 @@
{
lib,
cfg,
name,
writeTextDir,
}: let
inherit (lib) mapAttrsToList concatStringsSep;
lines = mapAttrsToList (key: value: ''${key} "${value}"'') cfg;
text = concatStringsSep "\n" lines;
in
writeTextDir "tf/cfg/${name}" text

View file

@ -10,6 +10,8 @@
curlWithGnuTls, curlWithGnuTls,
steamworks-sdk-redist, steamworks-sdk-redist,
system, system,
callPackage,
srcds-tf2,
}: let }: let
inherit (lib) importJSON map toString elem last replaceStrings naturalSort; inherit (lib) importJSON map toString elem last replaceStrings naturalSort;
depotInputs = importJSON ./depots.json; depotInputs = importJSON ./depots.json;
@ -59,12 +61,28 @@
} }
); );
makeWithConfig = base: config: let
configFile = callPackage ./cfg.nix {
name = "server.cfg";
cfg = config;
};
final = symlinkJoin {
name = "srcds-tf2-src";
paths = [base configFile];
passthru = makeWiths final;
};
in
final;
makeWiths = base: {
withConfig = makeWithConfig base;
};
mainProgram = mainProgram =
if system == "x86_64-linux" if system == "x86_64-linux"
then "srcds_run_64" then "srcds_run_64"
else "srcds_run"; else "srcds_run";
in in
stdenvNoCC.mkDerivation { stdenvNoCC.mkDerivation (finalAttrs: {
pname = "srcds-tf2"; pname = "srcds-tf2";
version = timeToVersion time; version = timeToVersion time;
inherit src; inherit src;
@ -96,6 +114,8 @@ in
runHook postInstall runHook postInstall
''; '';
passthru = makeWiths srcds-tf2;
meta = with lib; { meta = with lib; {
inherit mainProgram; inherit mainProgram;
description = "TF2 dedicated server"; description = "TF2 dedicated server";
@ -107,4 +127,4 @@ in
license = licenses.unfree; license = licenses.unfree;
platforms = ["x86_64-linux" "i686-linux"]; platforms = ["x86_64-linux" "i686-linux"];
}; };
} })