buck2: more cosmetic refactorings; NFC

Signed-off-by: Austin Seipp <aseipp@pobox.com>

+61 -43
+59 -41
pkgs/development/tools/build-managers/buck2/default.nix
··· 2 2 , testers, buck2 # for passthru.tests 3 3 }: 4 4 5 - let 6 - # NOTE (aseipp): buck2 uses a precompiled binary build for good reason — the 7 - # upstream codebase extensively uses unstable `rustc` nightly features, and as 8 - # a result can't be built upstream in any sane manner. it is only ever tested 9 - # and integrated against a single version of the compiler, which produces all 10 - # usable binaries. you shouldn't try to workaround this or get clever and 11 - # think you can patch it to work; just accept it for now. it is extremely 12 - # unlikely buck2 will build with a stable compiler anytime soon; see related 13 - # upstream issues: 14 - # 15 - # - NixOS/nixpkgs#226677 16 - # - NixOS/nixpkgs#232471 17 - # - facebook/buck2#265 18 - # - facebook/buck2#322 19 - # 20 - # worth noting: it *is* possible to build buck2 from source using 21 - # buildRustPackage, and it works fine, but only if you are using flakes and 22 - # can import `rust-overlay` from somewhere else to vendor your compiler. See 23 - # nixos/nixpkgs#226677 for more information about that. 5 + # NOTE (aseipp): buck2 uses a precompiled binary build for good reason — the 6 + # upstream codebase extensively uses unstable `rustc` nightly features, and as a 7 + # result can't be built upstream in any sane manner. it is only ever tested and 8 + # integrated against a single version of the compiler, which produces all usable 9 + # binaries. you shouldn't try to workaround this or get clever and think you can 10 + # patch it to work; just accept it for now. it is extremely unlikely buck2 will 11 + # build with a stable compiler anytime soon; see related upstream issues: 12 + # 13 + # - NixOS/nixpkgs#226677 14 + # - NixOS/nixpkgs#232471 15 + # - facebook/buck2#265 16 + # - facebook/buck2#322 17 + # 18 + # worth noting: it *is* possible to build buck2 from source using 19 + # buildRustPackage, and it works fine, but only if you are using flakes and can 20 + # import `rust-overlay` from somewhere else to vendor your compiler. See 21 + # nixos/nixpkgs#226677 for more information about that. 24 22 25 - # map our platform name to the rust toolchain suffix 26 - suffix = { 27 - x86_64-darwin = "x86_64-apple-darwin"; 28 - aarch64-darwin = "aarch64-apple-darwin"; 29 - x86_64-linux = "x86_64-unknown-linux-musl"; 30 - aarch64-linux = "aarch64-unknown-linux-musl"; 31 - }."${stdenv.hostPlatform.system}" or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); 23 + # NOTE (aseipp): this expression is mostly automated, and you are STRONGLY 24 + # RECOMMENDED to use to nix-update for updating this expression when new 25 + # releases come out, which runs the sibling `update.sh` script. 26 + # 27 + # from the root of the nixpkgs git repository, run: 28 + # 29 + # nix-shell maintainers/scripts/update.nix \ 30 + # --argstr commit true \ 31 + # --argstr package buck2 32 32 33 - allHashes = builtins.fromJSON (builtins.readFile ./hashes.json); 33 + let 34 + 35 + # build hashes, which correspond to the hashes of the precompiled binaries 36 + # procued by GitHub Actions. this also includes the hash for a download of a 37 + # compatible buck2-prelude 38 + buildHashes = builtins.fromJSON (builtins.readFile ./hashes.json); 34 39 35 40 # our version of buck2; this should be a git tag 36 - buck2-version = "2023-08-15"; 41 + version = "2023-08-15"; 42 + 43 + # the platform-specific, statically linked binary — which is also 44 + # zstd-compressed 37 45 src = 38 46 let 39 - name = "buck2-${buck2-version}-${suffix}.zst"; 40 - hash = allHashes."${stdenv.hostPlatform.system}"; 41 - url = "https://github.com/facebook/buck2/releases/download/${buck2-version}/buck2-${suffix}.zst"; 47 + suffix = { 48 + # map our platform name to the rust toolchain suffix 49 + # NOTE (aseipp): must be synchronized with update.sh! 50 + x86_64-darwin = "x86_64-apple-darwin"; 51 + aarch64-darwin = "aarch64-apple-darwin"; 52 + x86_64-linux = "x86_64-unknown-linux-musl"; 53 + aarch64-linux = "aarch64-unknown-linux-musl"; 54 + }."${stdenv.hostPlatform.system}" or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); 55 + 56 + name = "buck2-${version}-${suffix}.zst"; 57 + hash = buildHashes."${stdenv.hostPlatform.system}"; 58 + url = "https://github.com/facebook/buck2/releases/download/${version}/buck2-${suffix}.zst"; 42 59 in fetchurl { inherit name url hash; }; 43 60 44 - # compatible version of buck2 prelude; a git revision in the buck2-prelude repository 45 - buck2-prelude = "40d6fffd01f224d25a62d982f4a3f00b275a5677"; 61 + # compatible version of buck2 prelude; this is exported via passthru.prelude 62 + # for downstream consumers to use when they need to automate any kind of 63 + # tooling 46 64 prelude-src = 47 65 let 48 - name = "buck2-prelude-${buck2-version}.tar.gz"; 49 - hash = allHashes."_prelude"; 50 - url = "https://github.com/facebook/buck2-prelude/archive/${buck2-prelude}.tar.gz"; 66 + prelude-hash = "40d6fffd01f224d25a62d982f4a3f00b275a5677"; 67 + name = "buck2-prelude-${version}.tar.gz"; 68 + hash = buildHashes."_prelude"; 69 + url = "https://github.com/facebook/buck2-prelude/archive/${prelude-hash}.tar.gz"; 51 70 in fetchurl { inherit name url hash; }; 52 71 53 - in 54 - stdenv.mkDerivation rec { 72 + in stdenv.mkDerivation { 55 73 pname = "buck2"; 56 - version = "unstable-${buck2-version}"; # TODO (aseipp): kill 'unstable' once a non-prerelease is made 74 + version = "unstable-${version}"; # TODO (aseipp): kill 'unstable' once a non-prerelease is made 57 75 inherit src; 58 76 59 77 nativeBuildInputs = [ zstd ]; ··· 90 108 meta = with lib; { 91 109 description = "Fast, hermetic, multi-language build system"; 92 110 homepage = "https://buck2.build"; 93 - changelog = "https://github.com/facebook/buck2/releases/tag/${buck2-version}"; 111 + changelog = "https://github.com/facebook/buck2/releases/tag/${version}"; 94 112 license = with licenses; [ asl20 /* or */ mit ]; 95 - mainProgram = pname; 113 + mainProgram = "buck2"; 96 114 maintainers = with maintainers; [ thoughtpolice ]; 97 115 platforms = [ 98 116 "x86_64-linux" "aarch64-linux"
+2 -2
pkgs/development/tools/build-managers/buck2/update.sh
··· 41 41 echo "}" >> "$HFILE" 42 42 43 43 sed -i \ 44 - 's/buck2-version\s*=\s*".*";/buck2-version = "'"$VERSION"'";/' \ 44 + '0,/version\s*=\s*".*";/s//version = "'"$VERSION"'";/' \ 45 45 "$NFILE" 46 46 47 47 sed -i \ 48 - 's/buck2-prelude\s*=\s*".*";/buck2-prelude = "'"$PRELUDE_HASH"'";/' \ 48 + '0,/prelude-hash\s*=\s*".*";/s//prelude-hash = "'"$PRELUDE_HASH"'";/' \ 49 49 "$NFILE" 50 50 51 51 echo "Done; wrote $HFILE and updated version in $NFILE."