10 common-updater-scripts,
19 inherit (darwin.apple_sdk_11_0.frameworks)
26 stdenv' = if stdenv.hostPlatform.isDarwin then overrideSDK stdenv "11.0" else stdenv;
28 stdenv'.mkDerivation (finalAttrs: {
33 finalAttrs.passthru.sources.${stdenv.hostPlatform.system}
34 or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
37 # silence service.h error
38 NIX_CFLAGS_COMPILE = "-Wno-implicit-function-declaration";
43 ++ lib.optionals stdenv.hostPlatform.isx86_64 [
48 buildInputs = lib.optionals stdenv.hostPlatform.isx86_64 [
56 dontBuild = stdenv.hostPlatform.isAarch64;
57 enableParallelBuilding = true;
62 mkdir -p $out/{bin,share/icons/hicolor/scalable/apps}
64 cp ./bin/yabai $out/bin/yabai
65 ${lib.optionalString stdenv.hostPlatform.isx86_64 "cp ./assets/icon/icon.svg $out/share/icons/hicolor/scalable/apps/yabai.svg"}
66 installManPage ./doc/yabai.1
72 lib.optionalString stdenv.hostPlatform.isx86_64 # bash
74 # aarch64 code is compiled on all targets, which causes our Apple SDK headers to error out.
75 # Since multilib doesn't work on darwin i dont know of a better way of handling this.
76 substituteInPlace makefile \
77 --replace "-arch arm64e" "" \
78 --replace "-arch arm64" "" \
79 --replace "clang" "${stdenv.cc.targetPrefix}clang"
81 # `NSScreen::safeAreaInsets` is only available on macOS 12.0 and above, which frameworks aren't packaged.
82 # When a lower OS version is detected upstream just returns 0, so we can hardcode that at compile time.
83 # https://github.com/koekeishiya/yabai/blob/v4.0.2/src/workspace.m#L109
84 substituteInPlace src/workspace.m \
85 --replace 'return screen.safeAreaInsets.top;' 'return 0;'
89 tests.version = testers.testVersion {
91 version = "yabai-v${finalAttrs.version}";
95 # Unfortunately compiling yabai from source on aarch64-darwin is a bit complicated. We use the precompiled binary instead for now.
96 # See the comments on https://github.com/NixOS/nixpkgs/pull/188322 for more information.
97 "aarch64-darwin" = fetchzip {
98 url = "https://github.com/koekeishiya/yabai/releases/download/v${finalAttrs.version}/yabai-v${finalAttrs.version}.tar.gz";
99 hash = "sha256-wp5B24DYX1RYHS/3+4WRRCzVE6FyCzatJDpzJWrEIpQ=";
101 "x86_64-darwin" = fetchFromGitHub {
102 owner = "koekeishiya";
104 rev = "v${finalAttrs.version}";
105 hash = "sha256-hCwI6ziUR4yuJOv4MQXh3ufbausaDrG8XfjR+jIOeC4=";
109 updateScript = writeShellScript "update-yabai" ''
115 common-updater-scripts
118 NEW_VERSION=$(curl --silent https://api.github.com/repos/koekeishiya/yabai/releases/latest | jq '.tag_name | ltrimstr("v")' --raw-output)
119 if [[ "${finalAttrs.version}" = "$NEW_VERSION" ]]; then
120 echo "The new version same as the old version."
123 for platform in ${lib.escapeShellArgs finalAttrs.meta.platforms}; do
124 update-source-version "yabai" "$NEW_VERSION" --ignore-same-version --source-key="sources.$platform"
130 description = "Tiling window manager for macOS based on binary space partitioning";
132 yabai is a window management utility that is designed to work as an extension to the built-in
133 window manager of macOS. yabai allows you to control your windows, spaces and displays freely
134 using an intuitive command line interface and optionally set user-defined keyboard shortcuts
135 using skhd and other third-party software.
137 homepage = "https://github.com/koekeishiya/yabai";
138 changelog = "https://github.com/koekeishiya/yabai/blob/v${finalAttrs.version}/CHANGELOG.md";
139 license = lib.licenses.mit;
140 platforms = builtins.attrNames finalAttrs.passthru.sources;
141 mainProgram = "yabai";
142 maintainers = with lib.maintainers; [
148 with lib.sourceTypes;
149 lib.optionals stdenv.hostPlatform.isx86_64 [ fromSource ]
150 ++ lib.optionals stdenv.hostPlatform.isAarch64 [ binaryNativeCode ];