summaryrefslogtreecommitdiff
path: root/modules/system
diff options
context:
space:
mode:
authortoonn <toonn@toonn.io>2022-06-26 09:18:11 +0200
committertoonn <toonn@toonn.io>2022-09-13 14:57:50 +0200
commited1e73d01e439c80cb2088e0190410236beb5826 (patch)
tree9e71de33bc6bfb61f9f39d43a24835360eadb52d /modules/system
parentfbe795f39dbcc242ddc6f7ab01689617746d9402 (diff)
applications: Drop store prefix to generalize
While the Nix store is almost always at `/nix/store`, we shouldn't assume it to be. Checking only the trailing part of the link is less exact but removes this bad assumption. I also added a check for the symlink's contents when overwriting it to more accurately check whether we own it and should replace it.
Diffstat (limited to 'modules/system')
-rw-r--r--modules/system/applications.nix21
1 files changed, 11 insertions, 10 deletions
diff --git a/modules/system/applications.nix b/modules/system/applications.nix
index dfcfd4f..9dd8766 100644
--- a/modules/system/applications.nix
+++ b/modules/system/applications.nix
@@ -24,20 +24,21 @@ in
# Set up applications.
echo "setting up /Applications/Nix Apps..." >&2
+ ourLink () {
+ local link
+ link=$(readlink "$1")
+ [ -L "$1" ] && [ "''${link#*-}" = 'system-applications/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')
- ]
+ if ourLink ~/Applications; then
rm ~/Applications
- elif [ -L '~/Applications/Nix Apps'
- -a $(readlink '~/Applications/Nix Apps' | grep --quiet
- '/nix/store/.*-system-applications/Applications')
- ]
- rm '~/Applications/Nix Apps'
+ elif ourLink ~/Applications/'Nix Apps'; then
+ rm ~/Applications/'Nix Apps'
fi
- if [ ! -e '/Applications/Nix Apps' -o -L '/Applications/Nix Apps' ]; then
+ if [ ! -e '/Applications/Nix Apps' ] \
+ || ourLink '/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