hraban / mac-app-util

Fix .app programs installed by Nix on Mac
GNU Affero General Public License v3.0
137 stars 5 forks source link
apple common-lisp flakes macos nix plist plist-files plutil

** How to use in Nix

Use the home-manager module to "fix" your .app launchers:

Now you can launch Nix-installed apps using only your keyboard, using @@html:@@⌘ space@@html:@@.

*** Flakes

How to use this in nix-darwin or home-manager, assuming you use flakes:

+begin_src nix

{ inputs = {

...

mac-app-util.url = "github:hraban/mac-app-util";
#...

};

outputs = { nix-darwin , home-manager , mac-app-util , ... }: { darwinConfigurations = { MyHost = nix-darwin.lib.darwinSystem {

...

    modules = [
      mac-app-util.darwinModules.default

      # And if you also use home manager:
      home-manager.darwinModules.home-manager
      (
        { pkgs, config, inputs, ... }:
        {
          # To enable it for all users:
          home-manager.sharedModules = [
            mac-app-util.homeManagerModules.default
          ];

          # Or to enable it for a single user only:
          home-manager.users.foobar.imports = [
            #...
            mac-app-util.homeManagerModules.default
          ];
        }
      )

    ];
  };
};

}; }

+end_src

*** Non-flakes

Since I use flakes for home manager and nix-darwin I’m not 100% on how to do this, but I suspect that it’s similar to the above, at its core.

What will be different is the “plumbing”, i.e. how to get a reference to this app’s derivation. Here’s how:

+begin_src nix

let mac-app-util-src = pkgs.fetchFromGitHub { repo = "mac-app-util"; owner = "hraban";

Replace these two lines by the corresponding entries from:

# $ nix run --experimental-features 'nix-command flakes' nixpkgs#nix-prefetch-github -- hraban mac-app-util
rev = "";
hash = "";

}; mac-app-util = (pkgs.callPackage mac-app-util-src {}); in

Now you have either the program as a derivation itself:

mac-app-util.default

Or the home manager module:

mac-app-util.homeManagerModules.default

Or darwin:

mac-app-util.darwinModules.default

+end_src

The rest is up to you. Good luck! ** Commands

At the core of this project is a (Nix-agnostic) program that can:

** mktrampoline

This creates a “trampoline” launcher app which is a simple wrapper application that just launches your actual application.

+begin_src shell

$ nix run github:hraban/mac-app-util -- mktrampoline /path/to/MyApp.app /Applications/MyApp.app

+end_src

Intuitively, you would either fully copy & paste the original .app, or create a symlink or “alias”; all of those solutions have different problems and they don’t get indexed by Spotlight properly.

This trampoline script is indexed by Spotlight and by Launchpad, so you can keep launching your apps using =⌘ SPC ⏎=

You can also wrap non-app stand-alone binaries with this. For example:

+begin_src shell

$ nix run github:hraban/mac-app-util -- mktrampoline "$(which darktable)" ~/Applications/Darktable.app

+end_src

Darktable is a photo editor available on Mac but without a .app bundle in the derivation. It’s just a stand-alone binary. Using mktrampoline, you can make it launchable from Spotlight.

See https://github.com/nix-community/home-manager/issues/1341

** sync-dock

When you have an app in your Dock which doesn’t live in =/Applications/..=, it can get stale: e.g. your app at =/foo/v1/Foo.app= gets replaced by =/foo/v2/Foo.app=. To automatically update the Dock to the new location of Foo, execute:

+begin_src shell

$ nix run github:hraban/mac-app-util -- sync-dock Foo.app

+end_src

It will find an old persistent item by the name of "Foo" and update it to the new location.

N.B.: This is currently limited only to Nix apps, but actually it could work for anything. I’ve just kept it conservative to be on the safe side.

** sync-trampolines

Combines =mktrampoline= and =sync-dock= to create a fresh directory with a fresh trampoline for every source app. E.g.:

+begin_src shell

$ nix run github:hraban/mac-app-util -- sync-trampolines ~/special/apps/ ~/Applications/Special/

+end_src

Will create a fresh directory (=~/Applications/Special=), deleting if it already existed. In that directory it will create a trampoline app for every single =*.app= file it finds in =~/special/apps/=.

This helps register apps from outside of your =~/Applications= directory with Spotlight and the Launchpad.

mac-app-util - Manage Mac App launchers Copyright © 2023–2024 Hraban Luyat

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.