Commit Graph
13 Commits
Author SHA1 Message Date
LGUG2Z b51eb8aab2 feat(nix): add nix-darwin module
This commit adds a nix-darwin module for komorebi and komorebi-bar,
exposed via `darwinModules.default` and `darwinModules.komorebi`.

The module provides the following options:

* `services.komorebi.enable`: enables the komorebi launchd agent
* `services.komorebi.config`: typed Nix configuration (defaults to example
  config)
* `services.komorebi.configFile`: path to a JSON config file (validated
  against schema)
* `services.komorebi.logLevel`: log verbosity level
* `services.komorebi.applicationSpecificConfiguration`: fetches
  app-specific configs from remote GitHub repositories at pinned
  revisions

* `services.komorebi-bar.enable`: enables komorebi-bar launchd agent(s)
* `services.komorebi-bar.bars.<name>`: named bar instances, one per
  monitor
* `services.komorebi-bar.bars.<name>.config`: typed Nix configuration per
  bar
* `services.komorebi-bar.bars.<name>.configFile`: path to a JSON config
  file per bar

The applicationSpecificConfiguration option supports multiple sources,
allowing users to combine the upstream default from
LGUG2Z/komorebi-application-specific-configuration with their own
personal overrides from other repositories.

When configFile is specified, the JSON file is validated against the
flake's version of the schema before being passed to the binary.

A new flake check, `darwin-module-validation`, validates the module
options and exercises the configFile validation against the example
JSON files loaded into `komorebic` for the `quickstart` cmd.
2025-12-24 17:18:44 -08:00
LGUG2Z 23aca28267 build(nix): add generated module opts and validation
This commit adds NixOS module option generation for komorebi and
komorebi-bar configurations, along with a nix and JSONSchema validation
test harness that runs as part of `nix flake check`.

`schemars-nixgen` (same as `schemars-docgen`, not sure if I'm gonna
release this...) generates strongly-typed Nix option definitions from
the generated JSONSchema files, allowing users to write type-checked Nix
configurations that map directly to the config files.

This will eventually be plugged into a nix-darwin module which I have
yet to start writing.
2025-12-24 17:18:41 -08:00
LGUG2Z b922dc3faa refactor(nix): bring shell directly into flake and pin cargo 2025-12-24 08:36:18 -08:00
LGUG2Z 82de4dd230 build(nix): clean runtime build inputs 2025-11-30 13:47:08 -08:00
LGUG2Z 6b980a0360 fix(border): close nswindow on main thread
This commit addresses a bug that was introduced/made visible in a5cbb4d.

The nixpkgs flake input (tracking nixpkgs-unstable) was updated from
github:NixOS/nixpkgs/f6b44b2401525650256b977063dbcf830f762369 to
github:NixOS/nixpkgs/0d59e0290eefe0f12512043842d7096c4070f30e and as a
result the version of AppKit being linked against jumped from
2022.44.149 to 2487.50.124.

Builds prior to a5cbb4d were building against macOS 13 (Ventura) era
frameworks due to the use of compatability stubs in nixpkgs, whereas the
nixpkgs-unstable update in a5cbb4d now links against the actual running
system's framework versions (in this case, macOS 15).

With github:NixOS/nixpkgs/f6b44b2401525650256b977063dbcf830f762369:

```
❯ otool -L target/debug/komorebi | grep -E 'AppKit|Foundation|CoreFoundation|libSystem'
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1775.118.101)
        /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 2022.44.149)
        /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1775.118.101)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.100.5)
```

With github:NixOS/nixpkgs/0d59e0290eefe0f12512043842d7096c4070f30e

```
❯ otool -L target/debug/komorebi | grep -E 'AppKit|Foundation|CoreFoundation|libSystem'
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 2420.0.0)
        /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 2487.50.124)
        /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 2420.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1345.100.2)
```

Somewhere between macOS 13 and macOS 15 Apple added stricter
thread-safety assertions in the AppKit framework, which resulted in the
calls to `NSWindow::close()` in border.rs to crash on an assertion
failure ("transaction must be valid")

```
* thread #9, stop reason = EXC_BREAKPOINT (code=1, subcode=0x19e543cc0)
    frame #0: 0x000000019e543cc0 AppKit`-[NSWMWindowCoordinator performTransactionUsingBlock:] + 752
AppKit`-[NSWMWindowCoordinator performTransactionUsingBlock:]:
->  0x19e543cc0 <+752>: brk    #0x1
    0x19e543cc4 <+756>: adrp   x0, 827
    0x19e543cc8 <+760>: add    x0, x0, #0x4ba ; "assertion failure: transaction must be valid"
    0x19e543ccc <+764>: bl     0x19e6eb58c    ; symbol stub for: _os_crash
Target 0: (komorebi) stopped.
(lldb) bt
* thread #9, stop reason = EXC_BREAKPOINT (code=1, subcode=0x19e543cc0)
  * frame #0: 0x000000019e543cc0 AppKit`-[NSWMWindowCoordinator performTransactionUsingBlock:] + 752
    frame #1: 0x000000019e372a00 AppKit`-[NSWindow(NSWMWindowManagement) window:didUpdateWithChangedProperties:] + 104
    frame #2: 0x000000027a366720 WindowManagement`-[_WMWindow performUpdatesUsingBlock:] + 100
    frame #3: 0x000000027a365714 WindowManagement`-[_WMWindow applyTags😷] + 712
    frame #4: 0x000000027a365cf8 WindowManagement`-[_WMWindow setVisible:] + 84
    frame #5: 0x000000019d91b064 AppKit`-[NSWindow _setVisible:] + 268
    frame #6: 0x000000019da16df0 AppKit`-[NSWindow _doWindowWillBecomeHidden] + 88
    frame #7: 0x000000019e3662e0 AppKit`-[NSWindow _reallyDoOrderWindowOutRelativeTo:] + 160
    frame #8: 0x000000019e366794 AppKit`-[NSWindow _reallyDoOrderWindow:] + 80
    frame #9: 0x000000019e3669e4 AppKit`-[NSWindow _doOrderWindow:] + 264
    frame #10: 0x000000019e360c84 AppKit`-[NSWindow _finishClosingWindow] + 444
    frame #11: 0x000000019daa6cc8 AppKit`-[NSWindow _close] + 380
    frame #12: 0x0000000100c3380c komorebi`_$LT$$LP$$RP$$u20$as$u20$objc2..encode..EncodeArguments$GT$::__invoke::h1be54296556f108b(msg_send_fn=(libobjc.A.dylib`objc_msgSend), receiver=0x0000000132e09ea0, sel=Sel @ 0x0000000170b58e38, (null)=<unavailable>) at encode.rs:433:26
    frame #13: 0x0000000100c30f84 komorebi`objc2::runtime::message_receiver::msg_send_primitive::send::h0de1c4d240a2223f(receiver=0x0000000132e09ea0, sel=Sel @ 0x0000000170b58e78, args=<unavailable>) at message_receiver.rs:172:18
    frame #14: 0x0000000100c2e904 komorebi`objc2::runtime::message_receiver::MessageReceiver::send_message::h86c04ca17a2b6faf(self=0x0000000132e09ea0, sel=Sel @ 0x0000000170b58ed0, args=<unavailable>) at message_receiver.rs:432:38
    frame #15: 0x0000000100b9b1bc komorebi`_$LT$MethodFamily$u20$as$u20$objc2..__macro_helpers..msg_send_retained..MsgSend$LT$Receiver$C$Return$GT$$GT$::send_message::h6cb30a52e558d44c(receiver=0x0000000132e09ea0, sel=Sel @ 0x0000000170b58f48, args=<unavailable>) at msg_send_retained.rs:35:28
    frame #16: 0x0000000100ba14b8 komorebi`objc2_app_kit::generated::__NSWindow::NSWindow::close::h34bc4ef6fc286b23(self=0x0000000132e09ea0) at extern_methods.rs:266:14
    frame #17: 0x00000001002b22f0 komorebi`komorebi::border_manager::border::Border::destroy::_$u7b$$u7b$closure$u7d$$u7d$::h61d54fa62ea0b107((null)=AutoreleasePool @ 0x0000000170b58fb8) at border.rs:161:35
```

To fix this, this commit ensures that the call to `NSWindow::close()` is
made on the main thread using `DispatchQueue::main().exec_sync()`.
2025-11-29 14:09:26 -08:00
LGUG2Z 0b34b8bfb1 build(nix): use flake-parts and treefmt 2025-11-28 13:27:04 -08:00
LGUG2Z db8cf858ff build(nix): pull git rev info from flake inputs
This commit adds a new workspace crate, version, which is consumed by
komorebi and komorebic.

If either of those binaries are being built by
the Nix Flake, the git rev info will be pulled from inputs.self.rev
instead of querying the git repo, because the git files are not passed
to the derivation.

The build.rs for the version crate decides if the build is happening by
querying the shadow-rs build output for BRANCH, which will always be
empty when a "nix build" is running.

Cargo builds will use the standard git information retrieval mechanisms
in shadow-rs.

The information in both cases is exposed as version::LONG_VERSION, and
passed to clap as the string to return when either binary is called with
the --version flag.
2025-11-06 16:57:17 -08:00
LGUG2Z a2831d2b7f ci(github): run checks and build with nix 2025-10-20 16:09:19 -07:00
LGUG2Z a9029fee41 build(nix): separate targets and add flake overlays 2025-10-19 11:32:15 -07:00
LGUG2Z de2c105fe1 chore(deps): flake.lock: Update
Flake lock file updates:

• Updated input 'crane':
    'github:ipetkov/crane/d599ae4847e7f87603e7082d73ca673aa93c916d' (2025-09-06)
  → 'github:ipetkov/crane/a669fe77a8b0cd6f11419d89ea45a16691ca5121' (2025-09-18)
• Updated input 'nixpkgs':
    'github:nixos/nixpkgs/c23193b943c6c689d70ee98ce3128239ed9e32d1' (2025-09-13)
  → 'github:nixos/nixpkgs/8eaee110344796db060382e15d3af0a9fc396e0e' (2025-09-19)
• Updated input 'rust-overlay':
    'github:oxalica/rust-overlay/09442765a05c2ca617c20ed68d9613da92a2d96b' (2025-09-15)
  → 'github:oxalica/rust-overlay/d2bac276ac7e669a1f09c48614538a37e3eb6d0f' (2025-09-22)
2025-09-22 15:02:23 -07:00
LGUG2Z 84d27f83e0 fix(wm): make hidden windows take up less space 2025-09-22 14:26:21 -07:00
LGUG2Z df9ceee17e feat(wm): migrate ipc and impl basic socket messages
This commit migrates another bunch of code from komorebi to start
implementing inter-process communication using Unix domain sockets.

For this commit a small subsection of the SocketMessage with maximum
utility has been migrated: FocusWindow, MoveWindow, ChangeLayout, and
TogglePause.

This includes migrating their handlers in process_command, and setting
up a UnixListener when creating a WindowManager instance.

To be able to test this functionality I also implemented a basic
skeleton of komorebic and migrated the komorebi-client library.

There are some random fixes included here now that we are listening to a
UnixListener on a separate thread, which includes wrapping structs from
the objc2 crate which don't have Send and Sync implemented, so that they
can be implemented in the komorebi lib.

I also took the time to figure out how to calculate a monitor's work
area size, excluding the dock and the menu bar, and started to split out
Workspace and Monitor into their own modules.

It looks like a lot of changes but most if this is just pulling in stuff
from the Windows implementation.
2025-09-17 16:18:06 -07:00
LGUG2Z 2b99a68ed8 feat(wm): initial commit 2025-09-16 16:53:11 -07:00