Repository navigation
feat(cua-driver): register the nur-packages driver with Claude Code #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
418f641
feat(cua-driver): install the pinned driver and register it with Clau…
NoSugarCoffee 7faef39
refactor(cua-driver): consume the package from nur-packages
NoSugarCoffee ef98075
fix(cua-driver): keep a single stamped CuaDriver.app
NoSugarCoffee b590621
test(cua-driver): cover copy failure and stamped replacement
NoSugarCoffee 32e4488
chore(flake): track nur-packages main for cua-driver
NoSugarCoffee 253a561
fix(cua-driver): make the staged app writable before stamping
NoSugarCoffee 203cfea
fix(cua-driver): leave MCP registration to dotai
NoSugarCoffee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| { | ||
| config, | ||
| lib, | ||
| pkgs, | ||
| homeDirectory, | ||
| ... | ||
| }: | ||
| let | ||
| # The signed release lives in NoSugarCoffee/nur-packages. This module only | ||
| # puts the CLI on PATH and copies the macOS bundle to the path `mcp` | ||
| # relaunches. Claude Code's MCP server list is owned by dotai (APM), not | ||
| # by a switch. | ||
| cua-driver = pkgs.nosugarcoffee.cua-driver or null; | ||
|
|
||
| # The package also ships $out/Applications/CuaDriver.app. home.packages | ||
| # feeds copyApps, which links every package's /Applications into | ||
| # ~/Applications/Home Manager Apps. This nixpkgs buildEnv lndirs the | ||
| # whole package and does not honor pathsToLink, so a symlinkJoin would | ||
| # still expose the bundle. Link only the CLI. The wrapper script execs | ||
| # the store bundle or /Applications/CuaDriver.app by absolute path. | ||
| cuaDriverBin = | ||
| if cua-driver == null then | ||
| null | ||
| else | ||
| pkgs.runCommand "cua-driver" { } '' | ||
| mkdir -p "$out/bin" | ||
| ln -s "${cua-driver}/bin/cua-driver" "$out/bin/cua-driver" | ||
| ''; | ||
| in | ||
| { | ||
| home = { | ||
| packages = lib.optional (cuaDriverBin != null) cuaDriverBin; | ||
|
|
||
| file = lib.mkIf (cua-driver != null) { | ||
| # The driver's own skill directory, and the Claude Code link. The | ||
| # Claude link targets the home copy so `cua-driver skills install` | ||
| # sees one pack. | ||
| ".cua-driver/skills/cua-driver".source = cua-driver.skills; | ||
| ".claude/skills/cua-driver".source = | ||
| config.lib.file.mkOutOfStoreSymlink "${homeDirectory}/.cua-driver/skills/cua-driver"; | ||
| }; | ||
|
|
||
| activation = { | ||
| # A real directory, not a symlink: TCC grants and the relaunch are | ||
| # keyed to /Applications/CuaDriver.app. Ownership matches copyApps: | ||
| # `home-manager.copied` on the bundle directory. A bundle without | ||
| # that stamp (the upstream installer) is left alone. | ||
| cuaDriverApp = lib.mkIf (cua-driver != null && pkgs.stdenv.isDarwin) ( | ||
| lib.hm.dag.entryAfter [ "copyApps" ] '' | ||
| sourceApp=${lib.escapeShellArg "${cua-driver}/Applications/CuaDriver.app"} | ||
| dest=/Applications/CuaDriver.app | ||
| destParent=$(dirname "$dest") | ||
| staging="$destParent/.CuaDriver.app.hm-new" | ||
| marker=${lib.escapeShellArg "${config.xdg.stateHome}/home-manager/cua-driver-app-source"} | ||
|
|
||
| # Same sentinel as copyApps in home.nix. An xattr on the .app | ||
| # directory, not a file inside the bundle (that would break the | ||
| # signature). The hidden file is the non-Darwin stand-in. | ||
| copySentinelAttr=home-manager.copied | ||
| copySentinelFile=.home-manager-copied | ||
|
|
||
| hasCopySentinel() { | ||
| local app="$1" | ||
| if [[ "$(uname -s)" == Darwin ]]; then | ||
| /usr/bin/xattr -p "$copySentinelAttr" "$app" >/dev/null 2>&1 | ||
| else | ||
| [[ -f "$app/$copySentinelFile" ]] | ||
| fi | ||
| } | ||
|
|
||
| writeCopySentinel() { | ||
| local app="$1" value="$2" | ||
| if [[ "$(uname -s)" == Darwin ]]; then | ||
| /usr/bin/xattr -w "$copySentinelAttr" "$value" "$app" | ||
| else | ||
| printf '%s' "$value" > "$app/$copySentinelFile" | ||
| fi | ||
| } | ||
|
|
||
| if [[ ! -w "$destParent" ]]; then | ||
| warnEcho "cua-driver: $destParent is not writable, so CuaDriver.app was not copied. mcp relaunches /Applications/CuaDriver.app; grant write access there and switch again." | ||
| elif [[ -e "$dest" ]] && ! hasCopySentinel "$dest"; then | ||
| warnEcho "cua-driver: $dest already exists and was not placed by home-manager; leaving it in place" | ||
| elif [[ -d "$dest" && "$(readlink "$marker" 2>/dev/null || true)" == "$sourceApp" ]]; then | ||
| : | ||
| elif [[ -v DRY_RUN ]]; then | ||
| echo "would copy $sourceApp to $dest" >&2 | ||
| else | ||
| $DRY_RUN_CMD mkdir -p "$(dirname "$marker")" | ||
| $DRY_RUN_CMD rm -rf "$staging" | ||
| # The store bundle is mode 555. ditto keeps that, and xattr/rm then | ||
| # fail on the staged copy (macOS CI aborted the whole switch). | ||
| # Owner can chmod a 555 tree; the signature hashes contents, not mode. | ||
| if ! $DRY_RUN_CMD /usr/bin/ditto "$sourceApp" "$staging"; then | ||
| warnEcho "cua-driver: copying CuaDriver.app to $destParent failed" | ||
| elif ! $DRY_RUN_CMD /bin/chmod -R u+w "$staging"; then | ||
| warnEcho "cua-driver: could not make the staged CuaDriver.app writable" | ||
| $DRY_RUN_CMD rm -rf "$staging" || warnEcho "cua-driver: could not remove $staging" | ||
| elif ! $DRY_RUN_CMD /usr/bin/codesign --verify --deep --strict "$staging"; then | ||
| warnEcho "cua-driver: copied CuaDriver.app failed signature verification; the previous app was left in place" | ||
| $DRY_RUN_CMD rm -rf "$staging" || warnEcho "cua-driver: could not remove $staging" | ||
| elif ! writeCopySentinel "$staging" "$sourceApp"; then | ||
| warnEcho "cua-driver: failed to stamp CuaDriver.app; leaving the previous app in place" | ||
| $DRY_RUN_CMD rm -rf "$staging" || warnEcho "cua-driver: could not remove $staging" | ||
| else | ||
| # Only reached when $dest is missing or already stamped. | ||
| # The running daemon holds the old binary. | ||
| if [[ -d "$dest" ]]; then | ||
| $DRY_RUN_CMD /usr/bin/pkill -x cua-driver || true | ||
| $DRY_RUN_CMD rm -rf "$dest" | ||
| fi | ||
| $DRY_RUN_CMD mv "$staging" "$dest" | ||
| writeCopySentinel "$dest" "$sourceApp" | ||
| $DRY_RUN_CMD ln -sfn "$sourceApp" "$marker" | ||
| fi | ||
| fi | ||
| '' | ||
| ); | ||
| }; | ||
| }; | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a future NUR update stops exposing
pkgs.nosugarcoffee.cua-driverfor a Darwin system, the module's package and activation are disabled bycua-driver == null, but this unconditional exception preventscopyAppsfrom removing the previously stamped bundle. The old app can therefore remain installed—and retain Accessibility and Screen Recording grants—despite no longer being declared; gate this exception on package availability or add an absent-package cleanup path for stamped copies.AGENTS.md reference: AGENTS.md:L29-L30
Useful? React with 👍 / 👎.