diff --git a/home/default.nix b/home/default.nix index 46edf95..0fbac83 100644 --- a/home/default.nix +++ b/home/default.nix @@ -13,6 +13,7 @@ # Programs and packages to manage with home manager. imports = [ + ./trampoline.nix ./terminal.nix ./secrets.nix ./ssh.nix diff --git a/home/trampoline.nix b/home/trampoline.nix new file mode 100644 index 0000000..bb8bff3 --- /dev/null +++ b/home/trampoline.nix @@ -0,0 +1,38 @@ +# Why: Applications installed by home-manager don't show up in spotlight. This +# module works around the issue. Can be removed if this is ever included +# in home-manager. +# Issue: https://github.com/nix-community/home-manager/issues/1341 +{ + config, + pkgs, + lib, + ... +}: { + home.activation = { + trampolineApps = let + apps = pkgs.buildEnv { + name = "home-manager-applications"; + paths = config.home.packages; + pathsToLink = "/Applications"; + }; + in + lib.hm.dag.entryAfter ["writeBoundary"] '' + toDir="$HOME/Applications/HMApps" + fromDir="${apps}/Applications" + rm -rf "$toDir" + mkdir "$toDir" + ( + cd "$fromDir" + for app in *.app; do + /usr/bin/osacompile -o "$toDir/$app" -e "do shell script \"open '$fromDir/$app'\"" + icon="$(/usr/bin/plutil -extract CFBundleIconFile raw "$fromDir/$app/Contents/Info.plist")" + if [[ $icon != *".icns" ]]; then + icon="$icon.icns" + fi + mkdir -p "$toDir/$app/Contents/Resources" + cp -f "$fromDir/$app/Contents/Resources/$icon" "$toDir/$app/Contents/Resources/applet.icns" + done + ) + ''; + }; +} diff --git a/nix-darwin/homebrew.nix b/nix-darwin/homebrew.nix index 3520640..4733920 100644 --- a/nix-darwin/homebrew.nix +++ b/nix-darwin/homebrew.nix @@ -16,14 +16,6 @@ # If an app isn't available in the Mac App Store, or the version in the App Store has # limitiations, e.g., Transmit, install the Homebrew Cask. homebrew.casks = [ - # Raycast - # Raycast is a blazingly fast, totally extendable launcher. It lets you - # complete tasks, calculate, share common links, and much more. - # https://www.raycast.com/ - # Why: Applications installed by home-manager don't show up in spotlight. - # Issue: https://github.com/nix-community/home-manager/issues/1341 - "raycast" - # 1password # A password manager, digital vault, form filler and secure digital wallet. # https://1password.com @@ -32,7 +24,7 @@ "1password" ]; - # For cli packages that aren't currently available for macOS in `nixpkgs`.Packages should be + # For cli packages that aren't currently available for macOS in `nixpkgs`. Packages should be # installed in `../home/default.nix` whenever possible. homebrew.brews = [ ]; diff --git a/trampoline.sh b/trampoline.sh new file mode 100755 index 0000000..fc1bf90 --- /dev/null +++ b/trampoline.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +# dest="/Users/${username}/Applications/Home Manager Trampolines/" +# src="${apps}/Applications/" +# rm -rf "$dest" && mkdir -p "$dest" +# export dest + +# for file do +# # escape the filename because space separated filenames suck +# filename="''${file@Q}" +# appname="$(basename "$file")" +# out="$dest/$appname" + +# # This is basically going to be the script body +# open_cmd=( +# "open" +# \"$file\" +# ) +# open_cmd="''${open_cmd[@]}" + +# # generate a wrapper app visible to spotlight +# wrapper=( +# "do" +# "shell" +# "script" +# "$open_cmd" +# ) +# wrapper="''${wrapper[@]}" +# /usr/bin/osacompile -o "$out" -e "$wrapper" 2>/dev/null + +# # time to make stuff visible in spotlight +# plutil=/usr/bin/plutil +# contents=/Contents +# resources="$contents/Resources" +# plist="$contents/Info.plist" + +# # splice in the icon +# icon="$("$plutil" -extract CFBundleIconFile raw "$file/$plist")" +# icon="''${icon%.icns}.icns" +# icon_src="$file/$resources/$icon" +# mkdir -p "$out/$resources" && cp "$icon_src" "$_/applet.icns" +# done + +function thing() { + files=("$@") + + for file in "${files[@]}"; do + + /usr/bin/osacompile -o "$toDir/$app" -e 'do shell script "open \"$fromDir/$app\""' + icon="$(/usr/bin/plutil -extract CFBundleIconFile raw "$fromDir/$app/Contents/Info.plist")" + mkdir -p "$toDir/$app/Contents/Resources" + cp -f "$fromDir/$app/Contents/Resources/$icon" "$toDir/$app/Contents/Resources/applet.icns" + + done +} + +export -f thing +find . -exec sh -c 'thing "$@"' sh {} +