Use the home-manager module to “fix” your .app launchers:
- Pinning in Dock works across updates
- Launch from Spotlight
- Create .app wrappers for non-app bundle, stand-alone binary programs
Now you can launch Nix-installed apps using only your keyboard, using ⌘ space.
How to use this in nix-darwin or home-manager, assuming you use flakes:
{
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
];
}
)
];
};
};
};
}
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:
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
The rest is up to you. Good luck!
At the core of this project is a (Nix-agnostic) program that can:
mktrampoline
- Create a “trampoline” launcher app
sync-dock
- Update persistent apps in the Dock
sync-trampolines
- Create a directory with trampolines to all your apps
This creates a “trampoline” launcher app which is a simple wrapper application that just launches your actual application.
$ nix run github:hraban/mac-app-util -- mktrampoline /path/to/MyApp.app /Applications/MyApp.app
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 <appname> ⏎
You can also wrap non-app stand-alone binaries with this. For example:
$ nix run github:hraban/mac-app-util -- mktrampoline "$(which darktable)" ~/Applications/Darktable.app
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 nix-community/home-manager#1341
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:
$ nix run github:hraban/mac-app-util -- sync-dock Foo.app
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.
Combines mktrampoline
and sync-dock
to create a fresh directory with a fresh trampoline for every source app. E.g.:
$ nix run github:hraban/mac-app-util -- sync-trampolines ~/special/apps/ ~/Applications/Special/
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/.