1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-13 20:30:02 +00:00

applications: Symlink Nix Apps to /Applications

This PR supercedes #226.

So far application bundles were always linked to `~/Applications` or
`~/Applications/Nix Apps` if the former was an existing directory.

In nix-community/home-manager#1341 a conflict was found with suggested
new Home Manager behavior, where applications installed through Home
Manager would end up in `~/Applications/Home Manager Apps`. This was in
an attempt to make them discoverable through Spotlight but further
investigation suggest Spotlight does not pick up symlinked apps (details
in the issue).

However, there are other programs that expect to be able to write to
`~/Applications` so taking over the directory is unfortunate.

PR #226 dropped linking `~/Applications` and instead made sure the
directory exists so we can always link in `~/Applications/Nix Apps`.

After further discussion in #macos:nixos.org we came to the conclusion
that we shouldn't link applications to a user directory at all. Since we
manage packages for multiple users, application bundles should go in
`/Applications`.

Because previous code will likely leave a symlink at
`~/Applications/{,Nix Apps}`, which will become dangling once the path
it links to is garbage collected from the store we test to see if a link
exists and it conforms to the path we're expecting and if it does remove
it.
This commit is contained in:
toonn 2022-06-25 13:12:54 +02:00
parent 9c76fbf20f
commit fbe795f39d
No known key found for this signature in database
GPG key ID: 44FF902A66DF4576

View file

@ -22,14 +22,25 @@ in
system.activationScripts.applications.text = ''
# Set up applications.
echo "setting up ~/Applications..." >&2
echo "setting up /Applications/Nix Apps..." >&2
mkdir -p ~/Applications
# Clean up for links created at the old location in HOME
if [ -L ~/Applications
-a $(readlink ~/Applications | grep --quiet
'/nix/store/.*-system-applications/Applications')
]
rm ~/Applications
elif [ -L '~/Applications/Nix Apps'
-a $(readlink '~/Applications/Nix Apps' | grep --quiet
'/nix/store/.*-system-applications/Applications')
]
rm '~/Applications/Nix Apps'
fi
if [ ! -e ~/Applications/Nix\ Apps -o -L ~/Applications/Nix\ Apps ]; then
ln -sfn ${cfg.build.applications}/Applications ~/Applications/Nix\ Apps
if [ ! -e '/Applications/Nix Apps' -o -L '/Applications/Nix Apps' ]; then
ln -sfn ${cfg.build.applications}/Applications '/Applications/Nix Apps'
else
echo "warning: ~/Applications/Nix Apps is not owned by nix-darwin, skipping App linking..." >&2
echo "warning: /Applications/Nix Apps is not owned by nix-darwin, skipping App linking..." >&2
fi
'';