From 5535f27d1d4fba38fd757b4bbf40aa09f17b8143 Mon Sep 17 00:00:00 2001 From: Milo <50248166+Milo123459@users.noreply.github.com> Date: Wed, 21 Sep 2022 16:57:59 +0000 Subject: [PATCH 1/2] bun: add auto-update script --- pkgs/development/web/bun/default.nix | 72 ++++++++++++++-------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/pkgs/development/web/bun/default.nix b/pkgs/development/web/bun/default.nix index a7487fb6c461..1954b5d808f7 100644 --- a/pkgs/development/web/bun/default.nix +++ b/pkgs/development/web/bun/default.nix @@ -1,40 +1,10 @@ -{ stdenvNoCC, callPackage, fetchurl, autoPatchelfHook, unzip, openssl, lib }: -let - dists = { - aarch64-darwin = { - arch = "aarch64"; - shortName = "darwin"; - sha256 = "sha256-R17Ga4C6PSxfL1bz6IBjx0dYFmX93i0y8uqxG1eZKd4="; - }; +{ stdenvNoCC, callPackage, fetchurl, autoPatchelfHook, unzip, openssl, lib, writeShellScript, curl, jq, common-updater-scripts }: - aarch64-linux = { - arch = "aarch64"; - shortName = "linux"; - sha256 = "sha256-KSC4gdsJZJoPjMEs+VigVuqlUDhg4sL054WRlAbB+eA="; - }; - - 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 +18,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 +64,6 @@ stdenvNoCC.mkDerivation rec { lgpl21Only # javascriptcore and webkit ]; maintainers = with maintainers; [ DAlperin jk ]; - platforms = builtins.attrNames dists; + platforms = builtins.attrNames passthru.sources; }; } From 0a08b8a83e5ced652bc16c2fbed4736f73da6cfc Mon Sep 17 00:00:00 2001 From: Milo <50248166+Milo123459@users.noreply.github.com> Date: Thu, 22 Sep 2022 07:17:00 +0100 Subject: [PATCH 2/2] Update pkgs/development/web/bun/default.nix Co-authored-by: Anderson Torres --- pkgs/development/web/bun/default.nix | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkgs/development/web/bun/default.nix b/pkgs/development/web/bun/default.nix index 1954b5d808f7..f91d00f6a6fd 100644 --- a/pkgs/development/web/bun/default.nix +++ b/pkgs/development/web/bun/default.nix @@ -1,4 +1,15 @@ -{ stdenvNoCC, callPackage, fetchurl, autoPatchelfHook, unzip, openssl, lib, writeShellScript, curl, jq, common-updater-scripts }: +{ lib +, stdenvNoCC +, callPackage +, fetchurl +, autoPatchelfHook +, unzip +, openssl +, writeShellScript +, curl +, jq +, common-updater-scripts +}: stdenvNoCC.mkDerivation rec { version = "0.1.13";