btrbk: add mainProgram
[NixPkgs.git] / pkgs / by-name / bu / bun / package.nix
blob67f147950d36315b5a3ba84a78232b2e1b2b88f7
1 { lib
2 , stdenvNoCC
3 , fetchurl
4 , autoPatchelfHook
5 , unzip
6 , installShellFiles
7 , openssl
8 , writeShellScript
9 , curl
10 , jq
11 , common-updater-scripts
14 stdenvNoCC.mkDerivation rec {
15   version = "1.1.31";
16   pname = "bun";
18   src = passthru.sources.${stdenvNoCC.hostPlatform.system} or (throw "Unsupported system: ${stdenvNoCC.hostPlatform.system}");
20   strictDeps = true;
21   nativeBuildInputs = [ unzip installShellFiles ] ++ lib.optionals stdenvNoCC.hostPlatform.isLinux [ autoPatchelfHook ];
22   buildInputs = [ openssl ];
24   dontConfigure = true;
25   dontBuild = true;
27   installPhase = ''
28     runHook preInstall
30     install -Dm 755 ./bun $out/bin/bun
31     ln -s $out/bin/bun $out/bin/bunx
33     runHook postInstall
34   '';
36   postPhases = lib.optionals (stdenvNoCC.buildPlatform.canExecute stdenvNoCC.hostPlatform) [ "postPatchelf" ];
37   postPatchelf = ''
38     completions_dir=$(mktemp -d)
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
44     installShellCompletion --name bun \
45       --bash $completions_dir/bun.completion.bash \
46       --zsh $completions_dir/_bun \
47       --fish $completions_dir/bun.fish
48   '';
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-dOQFfkxCiOFmAr11CjSdSKNpiLERkbVWawAuy8ASkJE=";
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-ZuU14GvAtf1n1sA8amtZUSGp5iJ5qp/SI2wrw4Gwe/4=";
59       };
60       "x86_64-darwin" = fetchurl {
61         url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-darwin-x64-baseline.zip";
62         hash = "sha256-qN8ciVHzHH8GgR89GDgfvteMV+YawMUQLiXNwYyN+wU=";
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-zHitG4Ktt+iCKk9GrC3C4MRSWhUxh89kW9bUeHzqNJs=";
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" "$NEW_VERSION" --ignore-same-version --source-key="sources.$platform"
79       done
80     '';
81   };
82   meta = with lib; {
83     homepage = "https://bun.sh";
84     changelog = "https://bun.sh/blog/bun-v${version}";
85     description = "Incredibly fast JavaScript runtime, bundler, transpiler and package manager – all in one";
86     sourceProvenance = with sourceTypes; [ binaryNativeCode ];
87     longDescription = ''
88       All in one fast & easy-to-use tool. Instead of 1,000 node_modules for development, you only need bun.
89     '';
90     license = with licenses; [
91       mit # bun core
92       lgpl21Only # javascriptcore and webkit
93     ];
94     mainProgram = "bun";
95     maintainers = with maintainers; [ DAlperin jk thilobillerbeck cdmistman coffeeispower diogomdp ];
96     platforms = builtins.attrNames passthru.sources;
97     # Broken for Musl at 2024-01-13, tracking issue:
98     # https://github.com/NixOS/nixpkgs/issues/280716
99     broken = stdenvNoCC.hostPlatform.isMusl;
100   };