about summary refs log tree commit diff
path: root/pkgs/os-specific/darwin
diff options
context:
space:
mode:
authorannalee <150648636+a-n-n-a-l-e-e@users.noreply.github.com>2024-03-25 18:04:41 +0000
committerannalee <150648636+a-n-n-a-l-e-e@users.noreply.github.com>2024-03-25 18:04:41 +0000
commit7541ec60b6f2d38b76e057135bb5942b78d3370c (patch)
tree319913607bb3ec024577259fdc2c561a651afba7 /pkgs/os-specific/darwin
parent90e2c2cda5f3650c46c00bebf02fcdc34129cbd4 (diff)
parent88e7ad7c3029b39166da303c8f30c8ee96ccd233 (diff)
Merge remote-tracking branch 'upstream/master' into staging-next
Diffstat (limited to 'pkgs/os-specific/darwin')
-rw-r--r--pkgs/os-specific/darwin/yabai/default.nix195
1 files changed, 82 insertions, 113 deletions
diff --git a/pkgs/os-specific/darwin/yabai/default.nix b/pkgs/os-specific/darwin/yabai/default.nix
index fa8067d8d478e..052e064276a6e 100644
--- a/pkgs/os-specific/darwin/yabai/default.nix
+++ b/pkgs/os-specific/darwin/yabai/default.nix
@@ -1,6 +1,5 @@
 { lib
 , stdenv
-, stdenvNoCC
 , fetchFromGitHub
 , fetchzip
 , installShellFiles
@@ -8,23 +7,90 @@
 , yabai
 , xxd
 , xcodebuild
-  # These all need to be from SDK 11.0 or later starting with yabai 5.0.0
 , Carbon
 , Cocoa
 , ScriptingBridge
 , SkyLight
 }:
 
-let
+stdenv.mkDerivation (finalAttrs: {
   pname = "yabai";
   version = "7.0.2";
 
-  test-version = testers.testVersion {
+  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}");
+
+  env = {
+    # silence service.h error
+    NIX_CFLAGS_COMPILE = "-Wno-implicit-function-declaration";
+  };
+
+  nativeBuildInputs = [
+    installShellFiles
+  ]
+  ++ lib.optionals stdenv.isx86_64 [
+    xcodebuild
+    xxd
+  ];
+
+  buildInputs = [ ] ++ lib.optionals stdenv.isx86_64 [
+    Carbon
+    Cocoa
+    ScriptingBridge
+    SkyLight
+  ];
+
+  dontConfigure = true;
+  dontBuild = stdenv.isAarch64;
+  enableParallelBuilding = true;
+
+  installPhase = ''
+    runHook preInstall
+
+    mkdir -p $out/{bin,share/icons/hicolor/scalable/apps}
+
+    cp ./bin/yabai $out/bin/yabai
+    ${lib.optionalString stdenv.isx86_64 "cp ./assets/icon/icon.svg $out/share/icons/hicolor/scalable/apps/yabai.svg"}
+    installManPage ./doc/yabai.1
+
+    runHook postInstall
+  '';
+
+  postPatch = lib.optionalString stdenv.isx86_64 /* bash */ ''
+    # aarch64 code is compiled on all targets, which causes our Apple SDK headers to error out.
+    # Since multilib doesnt work on darwin i dont know of a better way of handling this.
+    substituteInPlace makefile \
+    --replace "-arch arm64e" "" \
+    --replace "-arch arm64" "" \
+    --replace "clang" "${stdenv.cc.targetPrefix}clang"
+
+    # `NSScreen::safeAreaInsets` is only available on macOS 12.0 and above, which frameworks arent packaged.
+    # When a lower OS version is detected upstream just returns 0, so we can hardcode that at compiletime.
+    # https://github.com/koekeishiya/yabai/blob/v4.0.2/src/workspace.m#L109
+    substituteInPlace src/workspace.m \
+    --replace 'return screen.safeAreaInsets.top;' 'return 0;'
+  '';
+
+  passthru.tests.version = testers.testVersion {
     package = yabai;
-    version = "yabai-v${version}";
+    version = "yabai-v${finalAttrs.version}";
   };
 
-  _meta = with lib; {
+  meta = {
     description = "A tiling window manager for macOS based on binary space partitioning";
     longDescription = ''
       yabai is a window management utility that is designed to work as an extension to the built-in
@@ -33,119 +99,22 @@ let
       using skhd and other third-party software.
     '';
     homepage = "https://github.com/koekeishiya/yabai";
-    changelog = "https://github.com/koekeishiya/yabai/blob/v${version}/CHANGELOG.md";
-    license = licenses.mit;
-    platforms = platforms.darwin;
+    changelog = "https://github.com/koekeishiya/yabai/blob/v${finalAttrs.version}/CHANGELOG.md";
+    license = lib.licenses.mit;
+    platforms = lib.platforms.darwin;
     mainProgram = "yabai";
-    maintainers = with maintainers; [
+    maintainers = with lib.maintainers; [
       cmacrae
       shardy
       ivar
       khaneliman
     ];
-  };
-in
-{
-  # 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 = stdenvNoCC.mkDerivation {
-    inherit pname version;
-
-    src = fetchzip {
-      url = "https://github.com/koekeishiya/yabai/releases/download/v${version}/yabai-v${version}.tar.gz";
-      hash = "sha256-FeNiJJM5vdzFT9s7N9cTjLYxKEfzZnKE9br13lkQhJo=";
-    };
-
-    nativeBuildInputs = [
-      installShellFiles
+    sourceProvenance = with lib.sourceTypes; [ ]
+      ++ lib.optionals stdenv.isx86_64 [
+      fromSource
+    ] ++ lib.optionals stdenv.isAarch64 [
+      binaryNativeCode
     ];
-
-    dontConfigure = true;
-    dontBuild = true;
-
-    installPhase = ''
-      runHook preInstall
-
-      mkdir -p $out
-      cp -r ./bin $out
-      installManPage ./doc/yabai.1
-
-      runHook postInstall
-    '';
-
-    passthru.tests.version = test-version;
-
-    meta = _meta // {
-      sourceProvenance = with lib.sourceTypes; [
-        binaryNativeCode
-      ];
-    };
   };
+})
 
-  x86_64-darwin = stdenv.mkDerivation {
-    inherit pname version;
-
-    src = fetchFromGitHub {
-      owner = "koekeishiya";
-      repo = "yabai";
-      rev = "v${version}";
-      hash = "sha256-/MOAKsY7MlRWdvUQwHeITTeGJbCUdX7blZZAl2zXuic=";
-    };
-
-    nativeBuildInputs = [
-      installShellFiles
-      xcodebuild
-      xxd
-    ];
-
-    buildInputs = [
-      Carbon
-      Cocoa
-      ScriptingBridge
-      SkyLight
-    ];
-
-    dontConfigure = true;
-    enableParallelBuilding = true;
-
-    env = {
-      # silence service.h error
-      NIX_CFLAGS_COMPILE = "-Wno-implicit-function-declaration";
-    };
-
-    postPatch = ''
-      # aarch64 code is compiled on all targets, which causes our Apple SDK headers to error out.
-      # Since multilib doesnt work on darwin i dont know of a better way of handling this.
-      substituteInPlace makefile \
-        --replace "-arch arm64e" "" \
-        --replace "-arch arm64" "" \
-        --replace "clang" "${stdenv.cc.targetPrefix}clang"
-
-      # `NSScreen::safeAreaInsets` is only available on macOS 12.0 and above, which frameworks arent packaged.
-      # When a lower OS version is detected upstream just returns 0, so we can hardcode that at compiletime.
-      # https://github.com/koekeishiya/yabai/blob/v4.0.2/src/workspace.m#L109
-      substituteInPlace src/workspace.m \
-        --replace 'return screen.safeAreaInsets.top;' 'return 0;'
-    '';
-
-    installPhase = ''
-      runHook preInstall
-
-      mkdir -p $out/{bin,share/icons/hicolor/scalable/apps}
-
-      cp ./bin/yabai $out/bin/yabai
-      cp ./assets/icon/icon.svg $out/share/icons/hicolor/scalable/apps/yabai.svg
-      installManPage ./doc/yabai.1
-
-      runHook postInstall
-    '';
-
-    passthru.tests.version = test-version;
-
-    meta = _meta // {
-      sourceProvenance = with lib.sourceTypes; [
-        fromSource
-      ];
-    };
-  };
-}.${stdenv.hostPlatform.system} or (throw "Unsupported platform ${stdenv.hostPlatform.system}")