LnL7 / nix-darwin

nix modules for darwin
MIT License
3.13k stars 451 forks source link

applications not linked in a way finder can find them #1079

Open mknudsen opened 1 month ago

mknudsen commented 1 month ago

I have a bunch of apps installed through nix-darwin and I can launch them from command line, i.e. Zoom with zoom.

I also see them in /run/current-system/Applications/. I however cannot find them through finder. How do I make macOS aware or those apps?

darwin-rebuild check tells me everything is ok.

Here are my software versions

darwin-version 
24.11pre674705.b833ff01a0d6+darwin4

Darwin myhostname 24.0.0 Darwin Kernel Version 24.0.0: Mon Aug 12 20:49:48 PDT 2024; root:xnu-11215.1.10~2/RELEASE_ARM64_T8103 arm64
antoineco commented 1 month ago

There are multiple problems with the way macOS applications are added to the /Applications directory right now.

The thread at https://github.com/NixOS/nix/issues/7055 is very informative, and proposes an interesting solution which leverages filesystem aliases instead of symlinks: https://github.com/NixOS/nix/issues/7055#issuecomment-1250166187

emilazy commented 1 month ago

Aliases also have significant issues; see https://github.com/nix-community/home-manager/issues/1341 for discussion. Probably copying is the best solution. That’s what Homebrew settled on eventually too.

antoineco commented 1 month ago

@emilazy are you referring to these two points?

Aliases won't be categorized under "Applications" [by Spotlight]

Aliases are kind of awful to work with - you can't seem to create them from the CLI without pinging finder via AppleScript / osascript

emilazy commented 1 month ago

Yes, though also making aliases through Finder is a hack with its own set of problems so we’d want to use a native code solution to accomplish it even if we went that route. The Spotlight problem is pretty serious though. If there was something other than copying that worked well I expect Homebrew Cask would have already adopted it.

reckenrode commented 1 month ago

Aliases can be created programatically (e.g., https://github.com/reckenrode/mkalias). Finder should not be scripted. It undermines TCC. macOS 15 also requires explicit approve Finder of scripting in Security & Privacy, making the experience even worse (probably to discourage scripting of Finder because it’s effectively equivalent to having Full Disk Access).

(I’m also pretty sure aliases share similar limitations to the trampoline method with references to the store in the dock and services not being available until an aliased application has been launched, but it’s been so long since I looked into it that I don’t remember for sure.)

wellerbp commented 2 weeks ago

Is your concern simply finding them in spotlight?

mknudsen commented 2 weeks ago

Is your concern simply finding them in spotlight?

Yes, cmd + space happens to be the way I start most my apps.

fbettag commented 2 weeks ago

Same goes for Alfred, can't find it if it isn't in Applications.

Enzime commented 2 weeks ago

Raycast shows my nix-darwin (/Applications/Nix Apps) and home-manager (~/Applications/Home Manager Apps) apps correctly 👍

wellerbp commented 2 weeks ago

Is your concern simply finding them in spotlight?

Yes, cmd + space happens to be the way I start most my apps.

There are a few ways to accomplish this, at least of which I am aware, but each has a downside or limitation. The best option is to create a symlink in your Applications that will have all installed applications, cli tools, etc. appear as Other.

Try entering this block into your configuration:

in
        pkgs.lib.mkForce ''
          # Set up applications.
          echo "setting up /Applications..." >&2
          rm -rf /Applications/Nix\ Apps
          mkdir -p /Applications/Nix\ Apps
          find ${env}/Applications -maxdepth 1 -type l -exec readlink '{}' + |
          while read src; do
            app_name=$(basename "$src")
            echo "copying $src" >&2
            ${pkgs.mkalias}/bin/mkalias "$src" "/Applications/Nix Apps/$app_name"
          done
          find ${env}/Applications -maxdepth 1 -type l -exec readlink '{}' + |
        '';
fbettag commented 1 week ago

so for me, it works for most home-manager packages. (except discord for some reason) While for systempackages it does not work at all.