yabai: add passthru.updateScript

This commit is contained in:
Austin Horstman 2024-03-25 12:37:48 -05:00
parent ea503179c5
commit bb9a549d5c
No known key found for this signature in database
1 changed files with 43 additions and 22 deletions

View File

@ -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