diff --git a/pkgs/by-name/bu/buck2/hashes.json b/pkgs/by-name/bu/buck2/hashes.json index 0ceda19e31cb..a43b6382ea84 100644 --- a/pkgs/by-name/bu/buck2/hashes.json +++ b/pkgs/by-name/bu/buck2/hashes.json @@ -1,14 +1,21 @@ { - "rust-project-aarch64-linux": "sha256-Pm5lEIu0hzI5BuA/LuTKjBP8S63jiz1oSB0g9tSETGU=", - "buck2-aarch64-linux": "sha256-Gn/Q2P0Fs93SbOawhzv8Z9DgbrIUlQ+9E3PyCNsV1pk=", - "buck2-aarch64-darwin": "sha256-XtGs7g64s76AYhpFDbqSuSlblRauxJM0PaAk1MNNgxA=", - "buck2-x86_64-linux": "sha256-gVOho7p25okvAV8OqXppdtwOOEzqH7VWcJBT4l5CT2U=", - "rust-project-x86_64-darwin": "sha256-ePawMIfltPRK3mJJxI1BvGs6b2vIcgWzW2XTJykUsdI=", + "x86_64-linux": { + "buck2": "sha256-gVOho7p25okvAV8OqXppdtwOOEzqH7VWcJBT4l5CT2U=", + "rust-project": "sha256-HKctvCiXyGFzfHfB3Qj6qR2p46i5vaaZgPg2J827ou4=" + }, + "x86_64-darwin": { + "buck2": "sha256-wHk/tJJbupMsrcmXXNVXurfLY2TOSssMnuTZ7LNjASY=", + "rust-project": "sha256-ePawMIfltPRK3mJJxI1BvGs6b2vIcgWzW2XTJykUsdI=" + }, + "aarch64-linux": { + "buck2": "sha256-Gn/Q2P0Fs93SbOawhzv8Z9DgbrIUlQ+9E3PyCNsV1pk=", + "rust-project": "sha256-Pm5lEIu0hzI5BuA/LuTKjBP8S63jiz1oSB0g9tSETGU=" + }, + "aarch64-darwin": { + "buck2": "sha256-XtGs7g64s76AYhpFDbqSuSlblRauxJM0PaAk1MNNgxA=", + "rust-project": "sha256-CkyLLv41iJTKHVB0e355ZO2MV7NzQeiF1gtWEGF5oAY=" + }, "version": "2025-08-15", - "rust-project-x86_64-linux": "sha256-HKctvCiXyGFzfHfB3Qj6qR2p46i5vaaZgPg2J827ou4=", - "buck2-x86_64-darwin": "sha256-wHk/tJJbupMsrcmXXNVXurfLY2TOSssMnuTZ7LNjASY=", - "rust-project-aarch64-darwin": "sha256-CkyLLv41iJTKHVB0e355ZO2MV7NzQeiF1gtWEGF5oAY=", - "prelude_fod": "sha256-cyuOMi8x8q9gd6p1obnYYDVPxyONZ+y41AFXvSbUjC0=", - "_comment": "Generated by buck2 update.sh", - "prelude_git": "892cb85f5fc3258c7e4f89a836821ec4b8c7ee44" + "preludeGit": "892cb85f5fc3258c7e4f89a836821ec4b8c7ee44", + "preludeFod": "sha256-cyuOMi8x8q9gd6p1obnYYDVPxyONZ+y41AFXvSbUjC0=" } diff --git a/pkgs/by-name/bu/buck2/package.nix b/pkgs/by-name/bu/buck2/package.nix index 69d37644950d..49a25b6a6baa 100644 --- a/pkgs/by-name/bu/buck2/package.nix +++ b/pkgs/by-name/bu/buck2/package.nix @@ -43,9 +43,10 @@ let # procued by GitHub Actions. this also includes the hash for a download of a # compatible buck2-prelude buildHashes = builtins.fromJSON (builtins.readFile ./hashes.json); + archHashes = buildHashes.${stdenv.hostPlatform.system}; # map our platform name to the rust toolchain suffix - # NOTE (aseipp): must be synchronized with update.sh! + # NOTE (aseipp): must be synchronized with update.nu! platform-suffix = { x86_64-darwin = "x86_64-apple-darwin"; @@ -53,7 +54,7 @@ let x86_64-linux = "x86_64-unknown-linux-gnu"; aarch64-linux = "aarch64-unknown-linux-gnu"; } - ."${stdenv.hostPlatform.system}"; + .${stdenv.hostPlatform.system}; in stdenv.mkDerivation (finalAttrs: { pname = "buck2"; @@ -64,13 +65,13 @@ stdenv.mkDerivation (finalAttrs: { # zstd-compressed (fetchurl { url = "https://github.com/facebook/buck2/releases/download/${lib.removePrefix "unstable-" finalAttrs.version}/buck2-${platform-suffix}.zst"; - hash = buildHashes."buck2-${stdenv.hostPlatform.system}"; + hash = archHashes.buck2; }) # rust-project, which is used to provide IDE integration Buck2 Rust projects, # is part of the official distribution (fetchurl { url = "https://github.com/facebook/buck2/releases/download/${lib.removePrefix "unstable-" finalAttrs.version}/rust-project-${platform-suffix}.zst"; - hash = buildHashes."rust-project-${stdenv.hostPlatform.system}"; + hash = archHashes.rust-project; }) ]; @@ -124,11 +125,11 @@ stdenv.mkDerivation (finalAttrs: { # for downstream consumers to use when they need to automate any kind of # tooling prelude = fetchurl { - url = "https://github.com/facebook/buck2-prelude/archive/${buildHashes.prelude-git}.tar.gz"; - hash = buildHashes.prelude-fod; + url = "https://github.com/facebook/buck2-prelude/archive/${buildHashes.preludeGit}.tar.gz"; + hash = buildHashes.preludeFod; }; - updateScript = ./update.sh; + updateScript = ./update.nu; }; meta = { diff --git a/pkgs/by-name/bu/buck2/update.nu b/pkgs/by-name/bu/buck2/update.nu new file mode 100755 index 000000000000..dd43e7b834b6 --- /dev/null +++ b/pkgs/by-name/bu/buck2/update.nu @@ -0,0 +1,49 @@ +#!/usr/bin/env nix-shell +#! nix-shell -I ./. +#! nix-shell -i nu +#! nix-shell -p nushell nix + +const ARCHES = [ + { name: "x86_64-linux", target: "x86_64-unknown-linux-gnu" }, + { name: "x86_64-darwin", target: "x86_64-apple-darwin" }, + { name: "aarch64-linux", target: "aarch64-unknown-linux-gnu" }, + { name: "aarch64-darwin", target: "aarch64-apple-darwin" }, +]; + +const MANIFEST = "pkgs/by-name/bu/buck2/hashes.json" + +def main [] { + let version = http get "https://api.github.com/repos/facebook/buck2/releases" + | sort-by -r created_at + | where prerelease == true and name != "latest" + | first + | get name + + let preludeHash = http get $"https://github.com/facebook/buck2/releases/download/($version)/prelude_hash" | decode | str trim + let preludeFod = run-external "nix" "--extra-experimental-features" "nix-command" "store" "prefetch-file" "--json" $"https://github.com/facebook/buck2-prelude/archive/($preludeHash).tar.gz" | from json | get hash + + print $"Newest version: ($version)" + print $"Newest prelude hash: ($preludeHash)" + + let hashes = $ARCHES | par-each { + |arch| + + { + $arch.name: { + "buck2": (run-external "nix" "--extra-experimental-features" "nix-command" "store" "prefetch-file" "--json" $"https://github.com/facebook/buck2/releases/download/($version)/buck2-($arch.target).zst" | from json | get hash), + "rust-project": (run-external "nix" "--extra-experimental-features" "nix-command" "store" "prefetch-file" "--json" $"https://github.com/facebook/buck2/releases/download/($version)/rust-project-($arch.target).zst" | from json | get hash), + } + } + } | reduce { |val, accum| $accum | merge $val } + + let new_manifest = $hashes + | insert "version" $version + | insert "preludeGit" $preludeHash + | insert "preludeFod" $preludeFod + + $new_manifest + | to json + | append "\n" + | str join + | save -f $MANIFEST +} diff --git a/pkgs/by-name/bu/buck2/update.sh b/pkgs/by-name/bu/buck2/update.sh deleted file mode 100755 index e47bb079bea5..000000000000 --- a/pkgs/by-name/bu/buck2/update.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env nix-shell -#! nix-shell -I nixpkgs=./. -#! nix-shell -i bash -#! nix-shell -p curl jq common-updater-scripts nix coreutils -# shellcheck shell=bash -set -euo pipefail - -VERSION=$(curl -s https://api.github.com/repos/facebook/buck2/releases \ - | jq -r 'sort_by(.created_at) | reverse | - (map - (select ((.prerelease == true) and (.name != "latest"))) | - first - ) | .name') -PRELUDE_HASH=$(curl -sLo - "https://github.com/facebook/buck2/releases/download/${VERSION}/prelude_hash") -PRELUDE_DL_URL="https://github.com/facebook/buck2-prelude/archive/${PRELUDE_HASH}.tar.gz" - -echo "Latest buck2 prerelease: $VERSION" -echo "Compatible buck2-prelude hash: $PRELUDE_HASH" - -ARCHS=( - "x86_64-linux:x86_64-unknown-linux-gnu" - "x86_64-darwin:x86_64-apple-darwin" - "aarch64-linux:aarch64-unknown-linux-gnu" - "aarch64-darwin:aarch64-apple-darwin" -) - -NFILE=pkgs/by-name/bu/buck2/package.nix -HFILE=pkgs/by-name/bu/buck2/hashes.json - -declare -A outputJson=() -outputJson["version"]="$VERSION" -outputJson["prelude_git"]="$PRELUDE_HASH" -outputJson["prelude_fod"]="$(nix --extra-experimental-features nix-command store prefetch-file --json "$PRELUDE_DL_URL" | jq -r .hash)" - -for arch in "${ARCHS[@]}"; do - IFS=: read -r arch_name arch_target <<< "$arch" - outputJson["buck2-$arch_name"]="$(nix --extra-experimental-features nix-command store prefetch-file --json "https://github.com/facebook/buck2/releases/download/${VERSION}/buck2-${arch_target}.zst" | jq -r .hash)" - - outputJson["rust-project-$arch_name"]="$(nix --extra-experimental-features nix-command store prefetch-file --json "https://github.com/facebook/buck2/releases/download/${VERSION}/rust-project-${arch_target}.zst" | jq -r .hash)" -done - -outputJson["_comment"]="Generated by buck2 update.sh" -jq -n 'def _nwise($n): def nw: if length <= $n then . else .[0:$n] , (.[$n:] | nw) end; nw; [$ARGS.positional | _nwise(2) | {(.[0]): .[1]}] | add' --args "${outputJson[@]@k}" > "$HFILE" - -echo "Done; wrote $HFILE and updated version in $NFILE."