buck2: Use nushell for the updateScript

+75 -63
+18 -11
pkgs/by-name/bu/buck2/hashes.json
··· 1 { 2 - "rust-project-aarch64-linux": "sha256-Pm5lEIu0hzI5BuA/LuTKjBP8S63jiz1oSB0g9tSETGU=", 3 - "buck2-aarch64-linux": "sha256-Gn/Q2P0Fs93SbOawhzv8Z9DgbrIUlQ+9E3PyCNsV1pk=", 4 - "buck2-aarch64-darwin": "sha256-XtGs7g64s76AYhpFDbqSuSlblRauxJM0PaAk1MNNgxA=", 5 - "buck2-x86_64-linux": "sha256-gVOho7p25okvAV8OqXppdtwOOEzqH7VWcJBT4l5CT2U=", 6 - "rust-project-x86_64-darwin": "sha256-ePawMIfltPRK3mJJxI1BvGs6b2vIcgWzW2XTJykUsdI=", 7 "version": "2025-08-15", 8 - "rust-project-x86_64-linux": "sha256-HKctvCiXyGFzfHfB3Qj6qR2p46i5vaaZgPg2J827ou4=", 9 - "buck2-x86_64-darwin": "sha256-wHk/tJJbupMsrcmXXNVXurfLY2TOSssMnuTZ7LNjASY=", 10 - "rust-project-aarch64-darwin": "sha256-CkyLLv41iJTKHVB0e355ZO2MV7NzQeiF1gtWEGF5oAY=", 11 - "prelude_fod": "sha256-cyuOMi8x8q9gd6p1obnYYDVPxyONZ+y41AFXvSbUjC0=", 12 - "_comment": "Generated by buck2 update.sh", 13 - "prelude_git": "892cb85f5fc3258c7e4f89a836821ec4b8c7ee44" 14 }
··· 1 { 2 + "x86_64-linux": { 3 + "buck2": "sha256-gVOho7p25okvAV8OqXppdtwOOEzqH7VWcJBT4l5CT2U=", 4 + "rust-project": "sha256-HKctvCiXyGFzfHfB3Qj6qR2p46i5vaaZgPg2J827ou4=" 5 + }, 6 + "x86_64-darwin": { 7 + "buck2": "sha256-wHk/tJJbupMsrcmXXNVXurfLY2TOSssMnuTZ7LNjASY=", 8 + "rust-project": "sha256-ePawMIfltPRK3mJJxI1BvGs6b2vIcgWzW2XTJykUsdI=" 9 + }, 10 + "aarch64-linux": { 11 + "buck2": "sha256-Gn/Q2P0Fs93SbOawhzv8Z9DgbrIUlQ+9E3PyCNsV1pk=", 12 + "rust-project": "sha256-Pm5lEIu0hzI5BuA/LuTKjBP8S63jiz1oSB0g9tSETGU=" 13 + }, 14 + "aarch64-darwin": { 15 + "buck2": "sha256-XtGs7g64s76AYhpFDbqSuSlblRauxJM0PaAk1MNNgxA=", 16 + "rust-project": "sha256-CkyLLv41iJTKHVB0e355ZO2MV7NzQeiF1gtWEGF5oAY=" 17 + }, 18 "version": "2025-08-15", 19 + "preludeGit": "892cb85f5fc3258c7e4f89a836821ec4b8c7ee44", 20 + "preludeFod": "sha256-cyuOMi8x8q9gd6p1obnYYDVPxyONZ+y41AFXvSbUjC0=" 21 }
+8 -7
pkgs/by-name/bu/buck2/package.nix
··· 43 # procued by GitHub Actions. this also includes the hash for a download of a 44 # compatible buck2-prelude 45 buildHashes = builtins.fromJSON (builtins.readFile ./hashes.json); 46 47 # map our platform name to the rust toolchain suffix 48 - # NOTE (aseipp): must be synchronized with update.sh! 49 platform-suffix = 50 { 51 x86_64-darwin = "x86_64-apple-darwin"; ··· 53 x86_64-linux = "x86_64-unknown-linux-gnu"; 54 aarch64-linux = "aarch64-unknown-linux-gnu"; 55 } 56 - ."${stdenv.hostPlatform.system}"; 57 in 58 stdenv.mkDerivation (finalAttrs: { 59 pname = "buck2"; ··· 64 # zstd-compressed 65 (fetchurl { 66 url = "https://github.com/facebook/buck2/releases/download/${lib.removePrefix "unstable-" finalAttrs.version}/buck2-${platform-suffix}.zst"; 67 - hash = buildHashes."buck2-${stdenv.hostPlatform.system}"; 68 }) 69 # rust-project, which is used to provide IDE integration Buck2 Rust projects, 70 # is part of the official distribution 71 (fetchurl { 72 url = "https://github.com/facebook/buck2/releases/download/${lib.removePrefix "unstable-" finalAttrs.version}/rust-project-${platform-suffix}.zst"; 73 - hash = buildHashes."rust-project-${stdenv.hostPlatform.system}"; 74 }) 75 ]; 76 ··· 124 # for downstream consumers to use when they need to automate any kind of 125 # tooling 126 prelude = fetchurl { 127 - url = "https://github.com/facebook/buck2-prelude/archive/${buildHashes.prelude-git}.tar.gz"; 128 - hash = buildHashes.prelude-fod; 129 }; 130 131 - updateScript = ./update.sh; 132 }; 133 134 meta = {
··· 43 # procued by GitHub Actions. this also includes the hash for a download of a 44 # compatible buck2-prelude 45 buildHashes = builtins.fromJSON (builtins.readFile ./hashes.json); 46 + archHashes = buildHashes.${stdenv.hostPlatform.system}; 47 48 # map our platform name to the rust toolchain suffix 49 + # NOTE (aseipp): must be synchronized with update.nu! 50 platform-suffix = 51 { 52 x86_64-darwin = "x86_64-apple-darwin"; ··· 54 x86_64-linux = "x86_64-unknown-linux-gnu"; 55 aarch64-linux = "aarch64-unknown-linux-gnu"; 56 } 57 + .${stdenv.hostPlatform.system}; 58 in 59 stdenv.mkDerivation (finalAttrs: { 60 pname = "buck2"; ··· 65 # zstd-compressed 66 (fetchurl { 67 url = "https://github.com/facebook/buck2/releases/download/${lib.removePrefix "unstable-" finalAttrs.version}/buck2-${platform-suffix}.zst"; 68 + hash = archHashes.buck2; 69 }) 70 # rust-project, which is used to provide IDE integration Buck2 Rust projects, 71 # is part of the official distribution 72 (fetchurl { 73 url = "https://github.com/facebook/buck2/releases/download/${lib.removePrefix "unstable-" finalAttrs.version}/rust-project-${platform-suffix}.zst"; 74 + hash = archHashes.rust-project; 75 }) 76 ]; 77 ··· 125 # for downstream consumers to use when they need to automate any kind of 126 # tooling 127 prelude = fetchurl { 128 + url = "https://github.com/facebook/buck2-prelude/archive/${buildHashes.preludeGit}.tar.gz"; 129 + hash = buildHashes.preludeFod; 130 }; 131 132 + updateScript = ./update.nu; 133 }; 134 135 meta = {
+49
pkgs/by-name/bu/buck2/update.nu
···
··· 1 + #!/usr/bin/env nix-shell 2 + #! nix-shell -I ./. 3 + #! nix-shell -i nu 4 + #! nix-shell -p nushell nix 5 + 6 + const ARCHES = [ 7 + { name: "x86_64-linux", target: "x86_64-unknown-linux-gnu" }, 8 + { name: "x86_64-darwin", target: "x86_64-apple-darwin" }, 9 + { name: "aarch64-linux", target: "aarch64-unknown-linux-gnu" }, 10 + { name: "aarch64-darwin", target: "aarch64-apple-darwin" }, 11 + ]; 12 + 13 + const MANIFEST = "pkgs/by-name/bu/buck2/hashes.json" 14 + 15 + def main [] { 16 + let version = http get "https://api.github.com/repos/facebook/buck2/releases" 17 + | sort-by -r created_at 18 + | where prerelease == true and name != "latest" 19 + | first 20 + | get name 21 + 22 + let preludeHash = http get $"https://github.com/facebook/buck2/releases/download/($version)/prelude_hash" | decode | str trim 23 + 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 24 + 25 + print $"Newest version: ($version)" 26 + print $"Newest prelude hash: ($preludeHash)" 27 + 28 + let hashes = $ARCHES | par-each { 29 + |arch| 30 + 31 + { 32 + $arch.name: { 33 + "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), 34 + "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), 35 + } 36 + } 37 + } | reduce { |val, accum| $accum | merge $val } 38 + 39 + let new_manifest = $hashes 40 + | insert "version" $version 41 + | insert "preludeGit" $preludeHash 42 + | insert "preludeFod" $preludeFod 43 + 44 + $new_manifest 45 + | to json 46 + | append "\n" 47 + | str join 48 + | save -f $MANIFEST 49 + }
-45
pkgs/by-name/bu/buck2/update.sh
··· 1 - #!/usr/bin/env nix-shell 2 - #! nix-shell -I nixpkgs=./. 3 - #! nix-shell -i bash 4 - #! nix-shell -p curl jq common-updater-scripts nix coreutils 5 - # shellcheck shell=bash 6 - set -euo pipefail 7 - 8 - VERSION=$(curl -s https://api.github.com/repos/facebook/buck2/releases \ 9 - | jq -r 'sort_by(.created_at) | reverse | 10 - (map 11 - (select ((.prerelease == true) and (.name != "latest"))) | 12 - first 13 - ) | .name') 14 - PRELUDE_HASH=$(curl -sLo - "https://github.com/facebook/buck2/releases/download/${VERSION}/prelude_hash") 15 - PRELUDE_DL_URL="https://github.com/facebook/buck2-prelude/archive/${PRELUDE_HASH}.tar.gz" 16 - 17 - echo "Latest buck2 prerelease: $VERSION" 18 - echo "Compatible buck2-prelude hash: $PRELUDE_HASH" 19 - 20 - ARCHS=( 21 - "x86_64-linux:x86_64-unknown-linux-gnu" 22 - "x86_64-darwin:x86_64-apple-darwin" 23 - "aarch64-linux:aarch64-unknown-linux-gnu" 24 - "aarch64-darwin:aarch64-apple-darwin" 25 - ) 26 - 27 - NFILE=pkgs/by-name/bu/buck2/package.nix 28 - HFILE=pkgs/by-name/bu/buck2/hashes.json 29 - 30 - declare -A outputJson=() 31 - outputJson["version"]="$VERSION" 32 - outputJson["prelude_git"]="$PRELUDE_HASH" 33 - outputJson["prelude_fod"]="$(nix --extra-experimental-features nix-command store prefetch-file --json "$PRELUDE_DL_URL" | jq -r .hash)" 34 - 35 - for arch in "${ARCHS[@]}"; do 36 - IFS=: read -r arch_name arch_target <<< "$arch" 37 - 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)" 38 - 39 - 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)" 40 - done 41 - 42 - outputJson["_comment"]="Generated by buck2 update.sh" 43 - 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" 44 - 45 - echo "Done; wrote $HFILE and updated version in $NFILE."
···