1{ lib
2, stdenvNoCC
3, fetchurl
4, autoPatchelfHook
5, unzip
6, installShellFiles
7, openssl
8, writeShellScript
9, curl
10, jq
11, common-updater-scripts
12}:
13
14stdenvNoCC.mkDerivation rec {
15 version = "1.0.13";
16 pname = "bun";
17
18 src = passthru.sources.${stdenvNoCC.hostPlatform.system} or (throw "Unsupported system: ${stdenvNoCC.hostPlatform.system}");
19
20 strictDeps = true;
21 nativeBuildInputs = [ unzip installShellFiles ] ++ lib.optionals stdenvNoCC.isLinux [ autoPatchelfHook ];
22 buildInputs = [ openssl ];
23
24 dontConfigure = true;
25 dontBuild = true;
26
27 installPhase = ''
28 runHook preInstall
29
30 install -Dm 755 ./bun $out/bin/bun
31 ln -s $out/bin/bun $out/bin/bunx
32
33 runHook postInstall
34 '';
35
36 postPhases = [ "postPatchelf" ];
37 postPatchelf = lib.optionalString (stdenvNoCC.buildPlatform.canExecute stdenvNoCC.hostPlatform) ''
38 completions_dir=$(mktemp -d)
39
40 SHELL="bash" $out/bin/bun completions $completions_dir
41 SHELL="zsh" $out/bin/bun completions $completions_dir
42 SHELL="fish" $out/bin/bun completions $completions_dir
43
44 installShellCompletion --name bun \
45 --bash $completions_dir/bun.completion.bash \
46 --zsh $completions_dir/_bun \
47 --fish $completions_dir/bun.fish
48 '';
49
50 passthru = {
51 sources = {
52 "aarch64-darwin" = fetchurl {
53 url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-darwin-aarch64.zip";
54 hash = "sha256-HAcPrC/xFu9UHdpyF13OW3cXQEmpcyvtswaGAdHtnUE=";
55 };
56 "aarch64-linux" = fetchurl {
57 url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-linux-aarch64.zip";
58 hash = "sha256-dadj5YKpWOxWzn7z+ve3naHmfVsX4fAtNARruXyY/pM=";
59 };
60 "x86_64-darwin" = fetchurl {
61 url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-darwin-x64.zip";
62 hash = "sha256-QbiEZ1YRozE/af41c7/jI+DXAGAhjplTsMaZoCGKYTo=";
63 };
64 "x86_64-linux" = fetchurl {
65 url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-linux-x64.zip";
66 hash = "sha256-rOWXBvYJfhi+3fSv6ZDU5tZ51Nfy4nBIRaFOimRHHTs=";
67 };
68 };
69 updateScript = writeShellScript "update-bun" ''
70 set -o errexit
71 export PATH="${lib.makeBinPath [ curl jq common-updater-scripts ]}"
72 NEW_VERSION=$(curl --silent https://api.github.com/repos/oven-sh/bun/releases/latest | jq '.tag_name | ltrimstr("bun-v")' --raw-output)
73 if [[ "${version}" = "$NEW_VERSION" ]]; then
74 echo "The new version same as the old version."
75 exit 0
76 fi
77 for platform in ${lib.escapeShellArgs meta.platforms}; do
78 update-source-version "bun" "0" "${lib.fakeHash}" --source-key="sources.$platform"
79 update-source-version "bun" "$NEW_VERSION" --source-key="sources.$platform"
80 done
81 '';
82 };
83 meta = with lib; {
84 homepage = "https://bun.sh";
85 changelog = "https://bun.sh/blog/bun-v${version}";
86 description = "Incredibly fast JavaScript runtime, bundler, transpiler and package manager – all in one";
87 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
88 longDescription = ''
89 All in one fast & easy-to-use tool. Instead of 1,000 node_modules for development, you only need bun.
90 '';
91 license = with licenses; [
92 mit # bun core
93 lgpl21Only # javascriptcore and webkit
94 ];
95 maintainers = with maintainers; [ DAlperin jk thilobillerbeck cdmistman coffeeispower ];
96 platforms = builtins.attrNames passthru.sources;
97 };
98}