Unverified Commit bb9a549d authored by Austin Horstman's avatar Austin Horstman
Browse files

yabai: add passthru.updateScript

parent ea503179
Loading
Loading
Loading
Loading
+43 −22
Original line number Diff line number Diff line
@@ -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,11 +74,43 @@ stdenv.mkDerivation (finalAttrs: {
    --replace 'return screen.safeAreaInsets.top;' 'return 0;'
  '';

  passthru.tests.version = testers.testVersion {
  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 = {
    description = "A tiling window manager for macOS based on binary space partitioning";
    longDescription = ''
@@ -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