#! /usr/bin/env nu def main [what: string = "all"] { match $what { "all" => { update_all_depots update_sourcemod update_sdks update_addons update_includes update_plugins }, "depots" => update_all_depots, "sourcemod" => update_sourcemod, "sdks" => update_sdks, "addons" => update_addons, "includes" => update_includes, "plugins" => update_plugins, _ => { print $"Unknown argument ($what)" } } nix fmt } def update_sourcemod [] { print "Updating sourcemod..." nix-update --flake --use-update-script ambuild nix build .#ambuild nix-update --flake --use-update-script metamod-source nix build .#metamods.x86_64-linux.tf2 nix-update --flake --use-update-script sourcemod nix build .#sourcepawn nix build .#sourcemods.x86_64-linux.tf2 } def update_plugins [] { print "Updating plugins..." list_plugins | each {|plugin| NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-update --flake --use-update-script $"sourcemod-plugin-($plugin)" nix build $".#sourcemod-plugin-($plugin)" --option system i686-linux } # all F2 plugins are updated in one go nix-update --flake --use-update-script sourcemod-plugin-afk } def update_addons [] { print "Updating addons..." list_addons | each {|plugin| nix-update --flake --use-update-script $"sourcemod-addon-($plugin)"} } def update_includes [] { print "Updating includes..." 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 } def update_sdks [] { print "Updating sdks..." let sdks = open nix/sourcemod/hl2sdks.json | columns $sdks | each {|sdk| update_sdk $sdk} } 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_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 [] { print "Updating 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 } def list_addons [] { ls -s nix/sourcemod/addons/ | where type == file and ($it.name | str ends-with '.nix') and ($it.name != 'overlay.nix') | get name | str substring 0..-5 }