From 1d9037fc6c99da11babcab5db7cfcc0d11ff94d1 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 9 Jul 2026 16:50:06 +0200 Subject: [PATCH] add withConfig for srcds --- flake.nix | 27 +++++++++++++++++---------- nix/srcds/cfg.nix | 11 +++++++++++ nix/srcds/default.nix | 24 ++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 nix/srcds/cfg.nix diff --git a/flake.nix b/flake.nix index 45ac9f6..6806e63 100644 --- a/flake.nix +++ b/flake.nix @@ -45,16 +45,23 @@ steam-depots = pkgs.steam-depots; }; - packages = inheritPkgs [ - "ambuild" - "sourcepawn" - "sourcemod" - "sourcemod-includes" - "sourcemod-include-curl" - "sourcemod-include-library" - "sourcemod-include-steamworks" - "srcds-tf2" - ]; + packages = + inheritPkgs [ + "ambuild" + "sourcepawn" + "sourcemod" + "sourcemod-includes" + "sourcemod-include-curl" + "sourcemod-include-library" + "sourcemod-include-steamworks" + "srcds-tf2" + ] + // { + test = pkgs: + pkgs.srcds-tf2.withConfig { + hostname = "Spire Server"; + }; + }; checks = { buildTestScript = {pkgs, ...}: diff --git a/nix/srcds/cfg.nix b/nix/srcds/cfg.nix new file mode 100644 index 0000000..1568dea --- /dev/null +++ b/nix/srcds/cfg.nix @@ -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 diff --git a/nix/srcds/default.nix b/nix/srcds/default.nix index 855edf0..cd11a14 100644 --- a/nix/srcds/default.nix +++ b/nix/srcds/default.nix @@ -10,6 +10,8 @@ curlWithGnuTls, steamworks-sdk-redist, system, + callPackage, + srcds-tf2, }: let inherit (lib) importJSON map toString elem last replaceStrings naturalSort; 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 = if system == "x86_64-linux" then "srcds_run_64" else "srcds_run"; in - stdenvNoCC.mkDerivation { + stdenvNoCC.mkDerivation (finalAttrs: { pname = "srcds-tf2"; version = timeToVersion time; inherit src; @@ -96,6 +114,8 @@ in runHook postInstall ''; + passthru = makeWiths srcds-tf2; + meta = with lib; { inherit mainProgram; description = "TF2 dedicated server"; @@ -107,4 +127,4 @@ in license = licenses.unfree; platforms = ["x86_64-linux" "i686-linux"]; }; - } + })