about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--pkgs/development/web/bun/default.nix83
1 files changed, 48 insertions, 35 deletions
diff --git a/pkgs/development/web/bun/default.nix b/pkgs/development/web/bun/default.nix
index a7487fb6c4612..f91d00f6a6fd2 100644
--- a/pkgs/development/web/bun/default.nix
+++ b/pkgs/development/web/bun/default.nix
@@ -1,40 +1,21 @@
-{ stdenvNoCC, callPackage, fetchurl, autoPatchelfHook, unzip, openssl, lib }:
-let
-  dists = {
-    aarch64-darwin = {
-      arch = "aarch64";
-      shortName = "darwin";
-      sha256 = "sha256-R17Ga4C6PSxfL1bz6IBjx0dYFmX93i0y8uqxG1eZKd4=";
-    };
-
-    aarch64-linux = {
-      arch = "aarch64";
-      shortName = "linux";
-      sha256 = "sha256-KSC4gdsJZJoPjMEs+VigVuqlUDhg4sL054WRlAbB+eA=";
-    };
+{ lib
+, stdenvNoCC
+, callPackage
+, fetchurl
+, autoPatchelfHook
+, unzip
+, openssl
+, writeShellScript
+, curl
+, jq
+, common-updater-scripts
+}:
 
-    x86_64-darwin = {
-      arch = "x64";
-      shortName = "darwin";
-      sha256 = "sha256-CVqFPvZScNTudE2wgUctwGDgTyaMeN8dUNmLatcKo5M=";
-    };
-
-    x86_64-linux = {
-      arch = "x64";
-      shortName = "linux";
-      sha256 = "sha256-N3hGPyp9wvb7jjpaFLJcdNIRyLvegjAe+MiV2aMS1nE=";
-    };
-  };
-  dist = dists.${stdenvNoCC.hostPlatform.system} or (throw "Unsupported system: ${stdenvNoCC.hostPlatform.system}");
-in
 stdenvNoCC.mkDerivation rec {
-  version = "0.1.11";
+  version = "0.1.13";
   pname = "bun";
 
-  src = fetchurl {
-    url = "https://github.com/Jarred-Sumner/bun-releases-for-updater/releases/download/bun-v${version}/bun-${dist.shortName}-${dist.arch}.zip";
-    sha256 = dist.sha256;
-  };
+  src = passthru.sources.${stdenvNoCC.hostPlatform.system} or (throw "Unsupported system: ${stdenvNoCC.hostPlatform.system}");
 
   strictDeps = true;
   nativeBuildInputs = [ unzip ] ++ lib.optionals stdenvNoCC.isLinux [ autoPatchelfHook ];
@@ -48,7 +29,39 @@ stdenvNoCC.mkDerivation rec {
     install -Dm 755 ./bun $out/bin/bun
     runHook postInstall
   '';
-
+  passthru = {
+    sources = {
+      "aarch64-darwin" = fetchurl {
+        url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-darwin-aarch64.zip";
+        sha256 = "RYTRcc8xccRmxuKOXwX3bBWJSXLI2/XfH4/7ZdcUBdE=";
+      };
+      "aarch64-linux" = fetchurl {
+        url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-linux-aarch64.zip";
+        sha256 = "LixLrzSsgbXyfpFKiksM4zNS5iDU3tXOrr7fP8yJknM=";
+      };
+      "x86_64-darwin" = fetchurl {
+        url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-darwin-x64.zip";
+        sha256 = "SGZcT2uVy6egr99FzyaykUWLuZBqDsvbCM/lsgy//g0=";
+      };
+      "x86_64-linux" = fetchurl {
+        url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-linux-x64.zip";
+        sha256 = "ssZtJi+CEVn7MjPMqFkwv1lnwE7a7ttkmiuoT0Y6wao=";
+      };
+    };
+    updateScript = writeShellScript "update-bun" ''
+      set -o errexit
+      export PATH="${lib.makeBinPath [ curl jq common-updater-scripts ]}"
+      NEW_VERSION=$(curl --silent https://api.github.com/repos/oven-sh/bun/releases/latest | jq '.tag_name | ltrimstr("bun-v")' --raw-output)
+      if [[ "${version}" = "$NEW_VERSION" ]]; then
+          echo "The new version same as the old version."
+          exit 0
+      fi
+      for platform in ${lib.escapeShellArgs meta.platforms}; do
+        update-source-version "bun" "0" "${lib.fakeSha256}" --source-key="sources.$platform"
+        update-source-version "bun" "$NEW_VERSION" --source-key="sources.$platform"
+      done
+    '';
+  };
   meta = with lib; {
     homepage = "https://bun.sh";
     changelog = "https://github.com/Jarred-Sumner/bun/releases/tag/bun-v${version}";
@@ -62,6 +75,6 @@ stdenvNoCC.mkDerivation rec {
       lgpl21Only # javascriptcore and webkit
     ];
     maintainers = with maintainers; [ DAlperin jk ];
-    platforms = builtins.attrNames dists;
+    platforms = builtins.attrNames passthru.sources;
   };
 }