#! /usr/bin/env nu def main [] { # update_all_depots # nix-update --flake --use-update-script ambuild # nix build .#ambuild # nix-update --flake --version=$"(get_metamod_version)" metamod-source # nix build .#metamods.x86_64-linux.tf2 # nix-update --flake --use-update-script sourcemod # nix build .#sourcemods.x86_64-linux.tf2 # let sdks = open nix/sourcemod/hl2sdks.json | columns # $sdks | each {|sdk| update_sdk $sdk} # nix-update --flake --use-update-script sourcemod-include-curl # 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 list_plugins | each {|plugin| nix-update --flake --use-update-script $"sourcemod-plugin-($plugin)"} nix fmt } def update_sdk [sdk: string] { print $"Updating ($sdk) SDK" # some sdks might have identical files at some point, so their hash can be the same # nix-update will replace all occurences of the hash, which might not be correct # so we put a unique dummy value in there to work around this open nix/sourcemod/hl2sdks.json | update ([$sdk, "sha256"] | into cell-path) $"($sdk)-placeholder" | save -f nix/sourcemod/hl2sdks.json nix-update --flake --use-update-script $"hl2sdk.x86_64-linux.($sdk)" nix build .#sourcemods.x86_64-linux.tf2 } def get_metamod_version [] { let html = http get https://www.metamodsource.net/downloads.php/?branch=stable let branch = $html | query web --query h3 | first | first | parse --regex "from (?P[0-9.]+) Branch" | get branch | first 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 | date to-timezone UTC | format date '%Y-%m-%dT%H:%M:%S' { 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.x86_64-linux.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' } def list_plugins [] { ls -s nix/sourcemod/plugins/ | where type == file and ($it.name | str ends-with '.nix') and ($it.name != 'overlay.nix') | get name | str substring 0..-5 }