From 6bbab5abe1ccb0792717391f9f36775281c3d150 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 9 Jul 2026 00:17:59 +0200 Subject: [PATCH] update scripts for depots --- .gitignore | 1 + README.md | 4 +-- flake.nix | 16 +++++++++-- nix/overlay.nix | 6 ++-- nix/sourcemod/hl2sdks.json | 2 +- nix/srcds/depot.nix | 21 ++++++++++++++ nix/srcds/depots.json | 2 +- nix/srcds/overlay.nix | 14 ++++++++++ update-all.nu | 57 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 113 insertions(+), 10 deletions(-) create mode 100644 nix/srcds/depot.nix create mode 100644 nix/srcds/overlay.nix diff --git a/.gitignore b/.gitignore index 71090d8..d38ec2a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ result .direnv tmp +depots diff --git a/README.md b/README.md index 3d1e21c..37cf908 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,8 @@ sourcemod doesn't support all of them. #### i686-linux -`episode1`, `orangebox`, `css`, `hl2dm`, `dods`, `sdk2013`, `tf2`, `l4d`, `l4d2`, -`nucleardawn`, `csgo`, `insurgency`, `bms` and `doi` +`episode1`, `orangebox`, `css`, `hl2dm`, `dods`, `sdk2013`, `tf2`, `l4d`, +`l4d2`, `nucleardawn`, `csgo`, `insurgency`, `bms` and `doi` #### x86_64-linux diff --git a/flake.nix b/flake.nix index c2c80d5..9f3e026 100644 --- a/flake.nix +++ b/flake.nix @@ -43,7 +43,19 @@ metamods = pkgs.lib.mapAttrs (name: sdk: pkgs.metamod-source-builder {${name} = sdk;}) pkgs.hl2sdk; }; - packages = inheritPkgs ["ambuild" "hl2sdk" "sourcepawn" "metamod-source" "sourcemod" "sourcemod-includes" "sourcemod-include-curl" "sourcemod-include-library" "sourcemod-include-steamworks" "srcds-tf2"]; + packages = inheritPkgs [ + "ambuild" + "hl2sdk" + "sourcepawn" + "metamod-source" + "sourcemod" + "sourcemod-includes" + "sourcemod-include-curl" + "sourcemod-include-library" + "sourcemod-include-steamworks" + "srcds-tf2" + "steam-depots" + ]; checks = { buildTestScript = {pkgs, ...}: @@ -57,7 +69,7 @@ }; devShells.default = {pkgs, ...}: { - packages = with pkgs; [nix-update]; + packages = with pkgs; [nix-update depotdownloader]; }; }; } diff --git a/nix/overlay.nix b/nix/overlay.nix index 7c54c32..6dc4597 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -1,5 +1,3 @@ final: prev: -{ - srcds-tf2 = final.callPackage ./srcds {}; -} -// (import ./sourcemod/overlay.nix) final prev +(import ./sourcemod/overlay.nix) final prev +// (import ./srcds/overlay.nix) final prev diff --git a/nix/sourcemod/hl2sdks.json b/nix/sourcemod/hl2sdks.json index 02794c6..66c03b5 100644 --- a/nix/sourcemod/hl2sdks.json +++ b/nix/sourcemod/hl2sdks.json @@ -107,4 +107,4 @@ "rev": "0af9332394a4eb3fb904610543d266f54b7ad820", "sha256": "sha256-WbOVrECtCKUwZEdoGV9c80t3gU6WopKVS89N7cKdhjg=" } -} \ No newline at end of file +} diff --git a/nix/srcds/depot.nix b/nix/srcds/depot.nix new file mode 100644 index 0000000..74a1fb6 --- /dev/null +++ b/nix/srcds/depot.nix @@ -0,0 +1,21 @@ +{ + lib, + fetchSteam, + appId, + depotId, + hash ? null, +}: let + inherit (lib) toString importJSON findFirst; + depotInputs = importJSON ./depots.json; + depotInput = findFirst (depot: depot.app_id == appId && depot.depot_id == depotId) {} depotInputs; +in + fetchSteam { + name = "steam-depot-${toString appId}-${toString depotId}"; + inherit appId depotId; + manifestId = depotInput.manifest; + hash = + if (hash == null) + then depotInput.hash + else hash; + fileList = depotInput.file_list or []; + } diff --git a/nix/srcds/depots.json b/nix/srcds/depots.json index fe82f28..c8bf6e6 100644 --- a/nix/srcds/depots.json +++ b/nix/srcds/depots.json @@ -3,7 +3,7 @@ "app_id": 232250, "depot_id": 232256, "manifest": 698669566371320345, - "date": "2026-07-07T17:15:40Z", + "date": "2026-07-03T19:53:32+02:00", "hash": "sha256-PNG0Xz08ozVjqYN2XZHr1/4TmrITIZA0kLax3LGMqZY=" }, { diff --git a/nix/srcds/overlay.nix b/nix/srcds/overlay.nix new file mode 100644 index 0000000..700a41d --- /dev/null +++ b/nix/srcds/overlay.nix @@ -0,0 +1,14 @@ +final: prev: let + inherit (prev.lib) toString importJSON listToAttrs map; + depotInputs = importJSON ./depots.json; +in { + srcds-tf2 = final.callPackage ./default.nix {}; + steam-depots = listToAttrs (map (depot: { + name = "steam-depot-${toString depot.app_id}-${toString depot.depot_id}"; + value = final.callPackage ./depot.nix { + appId = depot.app_id; + depotId = depot.depot_id; + }; + }) + depotInputs); +} diff --git a/update-all.nu b/update-all.nu index 84f1a39..8283844 100755 --- a/update-all.nu +++ b/update-all.nu @@ -1,6 +1,8 @@ #! /usr/bin/env nu def main [] { + update_all_depots + nix-update --flake --use-update-script ambuild nix build .#ambuild @@ -17,6 +19,8 @@ def main [] { nix-update --flake --use-update-script sourcemod-include-library nix-update --flake --use-update-script sourcemod-include-steamworks nix-update --flake --use-update-script sourcemod-includes + + nix fmt } def update_sdk [sdk: string] { @@ -36,3 +40,56 @@ def get_metamod_version [] { let build = $html | query web --as-table [Build] | get Build | first $"($branch).0.($build)" } + +def get_manifest [app: int, depot: int] { + let info = DepotDownloader -app $app -depot $depot -manifest-only | parse -r 'Manifest (?P[0-9]+) \((?P[^)]+)\)' | first + # builting rm doesn't work for some reason? + env rm -r ./depots + let manifest = $info | get manifest | into int + let date = $info | get date | into datetime | format date '%+' + + { + app_id: $app, + depot_id: $depot, + manifest: $manifest, + date: $date, + } +} + +def update_all_depots [] { + let $depots = open nix/srcds/depots.json + let updated = $depots | each {|manifest| update_manifest $manifest} + + # save, so the nix build for determining the hashes sees the new manifest id + $updated | save -f nix/srcds/depots.json + + let with_hashes = $updated | each {|manifest| update_manifest_hash $manifest} + $with_hashes | save -f nix/srcds/depots.json +} + +def update_manifest [manifest: record] { + let new = get_manifest $manifest.app_id $manifest.depot_id + + if ($new.manifest != $manifest.manifest) { + $manifest | merge $new | merge {hash: ""} + } else { + $manifest + } +} + +def update_manifest_hash [manifest: record] { + if $manifest.hash == "" { + let new = get_manifest_hash $manifest + $manifest | merge {hash: $new} + } else { + $manifest + } +} + +def get_manifest_hash [manifest: record] { + nix build $".#steam-depots.steam-depot-($manifest.app_id)-($manifest.depot_id)" | complete | get 'stderr' | extract_hash +} + +def extract_hash [] { + parse -r "got: (?Psha256-[A-Za-z0-9+\/=]+)" | first | get 'hash' +}