From bb9a549d5ce39bcfd33f6adf1ef57a569b203c64 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Mon, 25 Mar 2024 12:37:48 -0500 Subject: [PATCH] yabai: add passthru.updateScript --- pkgs/os-specific/darwin/yabai/default.nix | 65 +++++++++++++++-------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/pkgs/os-specific/darwin/yabai/default.nix b/pkgs/os-specific/darwin/yabai/default.nix index 052e064276a6..509fbeddb2a3 100644 --- a/pkgs/os-specific/darwin/yabai/default.nix +++ b/pkgs/os-specific/darwin/yabai/default.nix @@ -4,9 +4,13 @@ , fetchzip , installShellFiles , testers -, yabai -, xxd +, writeShellScript +, common-updater-scripts +, curl +, jq , xcodebuild +, xxd +, yabai , Carbon , Cocoa , ScriptingBridge @@ -17,22 +21,7 @@ stdenv.mkDerivation (finalAttrs: { pname = "yabai"; version = "7.0.2"; - src = - # Unfortunately compiling yabai from source on aarch64-darwin is a bit complicated. We use the precompiled binary instead for now. - # See the comments on https://github.com/NixOS/nixpkgs/pull/188322 for more information. - if stdenv.isAarch64 then - (fetchzip { - url = "https://github.com/koekeishiya/yabai/releases/download/v${finalAttrs.version}/yabai-v${finalAttrs.version}.tar.gz"; - hash = "sha256-FeNiJJM5vdzFT9s7N9cTjLYxKEfzZnKE9br13lkQhJo="; - }) - else if stdenv.isx86_64 then - (fetchFromGitHub { - owner = "koekeishiya"; - repo = "yabai"; - rev = "v${finalAttrs.version}"; - hash = "sha256-/MOAKsY7MlRWdvUQwHeITTeGJbCUdX7blZZAl2zXuic="; - }) - else (throw "Unsupported system: ${stdenv.hostPlatform.system}"); + src = finalAttrs.passthru.sources.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); env = { # silence service.h error @@ -85,9 +74,41 @@ stdenv.mkDerivation (finalAttrs: { --replace 'return screen.safeAreaInsets.top;' 'return 0;' ''; - passthru.tests.version = testers.testVersion { - package = yabai; - version = "yabai-v${finalAttrs.version}"; + passthru = { + tests.version = testers.testVersion { + package = yabai; + version = "yabai-v${finalAttrs.version}"; + }; + + sources = { + # Unfortunately compiling yabai from source on aarch64-darwin is a bit complicated. We use the precompiled binary instead for now. + # See the comments on https://github.com/NixOS/nixpkgs/pull/188322 for more information. + "aarch64-darwin" = fetchzip { + url = "https://github.com/koekeishiya/yabai/releases/download/v${finalAttrs.version}/yabai-v${finalAttrs.version}.tar.gz"; + hash = "sha256-FeNiJJM5vdzFT9s7N9cTjLYxKEfzZnKE9br13lkQhJo="; + }; + "x86_64-darwin" = fetchFromGitHub + { + owner = "koekeishiya"; + repo = "yabai"; + rev = "v${finalAttrs.version}"; + hash = "sha256-/MOAKsY7MlRWdvUQwHeITTeGJbCUdX7blZZAl2zXuic="; + }; + }; + + updateScript = writeShellScript "update-yabai" '' + set -o errexit + export PATH="${lib.makeBinPath [ curl jq common-updater-scripts ]}" + NEW_VERSION=$(curl --silent https://api.github.com/repos/koekeishiya/yabai/releases/latest | jq '.tag_name | ltrimstr("v")' --raw-output) + if [[ "${finalAttrs.version}" = "$NEW_VERSION" ]]; then + echo "The new version same as the old version." + exit 0 + fi + for platform in ${lib.escapeShellArgs finalAttrs.meta.platforms}; do + update-source-version "yabai" "0" "${lib.fakeHash}" --source-key="sources.$platform" + update-source-version "yabai" "$NEW_VERSION" --source-key="sources.$platform" + done + ''; }; meta = { @@ -101,7 +122,7 @@ stdenv.mkDerivation (finalAttrs: { homepage = "https://github.com/koekeishiya/yabai"; changelog = "https://github.com/koekeishiya/yabai/blob/v${finalAttrs.version}/CHANGELOG.md"; license = lib.licenses.mit; - platforms = lib.platforms.darwin; + platforms = builtins.attrNames finalAttrs.passthru.sources; mainProgram = "yabai"; maintainers = with lib.maintainers; [ cmacrae