nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 buildPackages,
5 fetchurl,
6 installShellFiles,
7 versionCheckHook,
8 autoPatchelfHook,
9 zstd,
10}:
11
12# NOTE (aseipp): buck2 uses a precompiled binary build for good reason — the
13# upstream codebase extensively uses unstable `rustc` nightly features, and as a
14# result can't be built upstream in any sane manner. it is only ever tested and
15# integrated against a single version of the compiler, which produces all usable
16# binaries. you shouldn't try to workaround this or get clever and think you can
17# patch it to work; just accept it for now. it is extremely unlikely buck2 will
18# build with a stable compiler anytime soon; see related upstream issues:
19#
20# - NixOS/nixpkgs#226677
21# - NixOS/nixpkgs#232471
22# - facebook/buck2#265
23# - facebook/buck2#322
24#
25# worth noting: it *is* possible to build buck2 from source using
26# buildRustPackage, and it works fine, but only if you are using flakes and can
27# import `rust-overlay` from somewhere else to vendor your compiler. See
28# nixos/nixpkgs#226677 for more information about that.
29
30# NOTE (aseipp): this expression is mostly automated, and you are STRONGLY
31# RECOMMENDED to use to nix-update for updating this expression when new
32# releases come out, which runs the sibling `update.sh` script.
33#
34# from the root of the nixpkgs git repository, run:
35#
36# nix-shell maintainers/scripts/update.nix --argstr commit true --argstr package buck2
37
38let
39
40 # build hashes, which correspond to the hashes of the precompiled binaries
41 # procued by GitHub Actions. this also includes the hash for a download of a
42 # compatible buck2-prelude
43 buildHashes = builtins.fromJSON (builtins.readFile ./hashes.json);
44 archHashes = buildHashes.${stdenv.hostPlatform.system};
45
46 # map our platform name to the rust toolchain suffix
47 # NOTE (aseipp): must be synchronized with update.nu!
48 platform-suffix =
49 {
50 x86_64-darwin = "x86_64-apple-darwin";
51 aarch64-darwin = "aarch64-apple-darwin";
52 x86_64-linux = "x86_64-unknown-linux-gnu";
53 aarch64-linux = "aarch64-unknown-linux-gnu";
54 }
55 .${stdenv.hostPlatform.system};
56in
57stdenv.mkDerivation (finalAttrs: {
58 pname = "buck2";
59 version = "unstable-${buildHashes.version}"; # TODO (aseipp): kill 'unstable' once a non-prerelease is made
60
61 srcs = [
62 # the platform-specific binary — which is also
63 # zstd-compressed
64 (fetchurl {
65 url = "https://github.com/facebook/buck2/releases/download/${lib.removePrefix "unstable-" finalAttrs.version}/buck2-${platform-suffix}.zst";
66 hash = archHashes.buck2;
67 })
68 # rust-project, which is used to provide IDE integration Buck2 Rust projects,
69 # is part of the official distribution
70 (fetchurl {
71 url = "https://github.com/facebook/buck2/releases/download/${lib.removePrefix "unstable-" finalAttrs.version}/rust-project-${platform-suffix}.zst";
72 hash = archHashes.rust-project;
73 })
74 ];
75
76 unpackCmd = "unzstd $curSrc -o $(stripHash $curSrc)";
77 sourceRoot = ".";
78
79 strictDeps = true;
80 nativeBuildInputs = [
81 installShellFiles
82 zstd
83 ]
84 ++ lib.optionals stdenv.hostPlatform.isLinux [
85 autoPatchelfHook
86 ];
87
88 buildInputs = [
89 #225963
90 stdenv.cc.cc.libgcc or null
91 ];
92
93 installPhase = ''
94 runHook preInstall
95
96 install -D buck2* "$out/bin/buck2"
97 install -D rust-project* "$out/bin/rust-project"
98
99 runHook postInstall
100 '';
101
102 # Have to put this at a weird stage because if it is put in
103 # postInstall, preFixup, or postFixup, autoPatchelf wouldn't
104 # have run yet
105 preInstallCheck =
106 let
107 emulator = stdenv.hostPlatform.emulator buildPackages;
108 in
109 lib.optionalString (stdenv.hostPlatform.emulatorAvailable buildPackages) ''
110 installShellCompletion --cmd buck2 \
111 --bash <(${emulator} $out/bin/buck2 completion bash ) \
112 --fish <(${emulator} $out/bin/buck2 completion fish ) \
113 --zsh <(${emulator} $out/bin/buck2 completion zsh )
114 '';
115
116 doInstallCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
117 nativeInstallCheckInputs = [ versionCheckHook ];
118
119 # TODO: When --version returns a real output, remove this.
120 # Currently it just spits out a hash
121 preVersionCheck = "version=buck2";
122
123 passthru = {
124 # compatible version of buck2 prelude; this is exported via passthru.prelude
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 = {
136 description = "Fast, hermetic, multi-language build system";
137 homepage = "https://buck2.build";
138 changelog = "https://github.com/facebook/buck2/releases/tag/${lib.removePrefix "unstable-" finalAttrs.version}";
139 license = with lib.licenses; [
140 asl20 # or
141 mit
142 ];
143 mainProgram = "buck2";
144 sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];
145 maintainers = with lib.maintainers; [
146 thoughtpolice
147 lf-
148 _9999years
149 ];
150 platforms = [
151 "x86_64-linux"
152 "aarch64-linux"
153 "x86_64-darwin"
154 "aarch64-darwin"
155 ];
156 };
157})