copyApps: fix linkApps migration

Prior to this commit, the migration would not run as the condition in `ourLink`
would not be fulfilled by the symlink created by `linkApps`.
This commit is contained in:
Michael Hoang 2026-04-11 14:48:20 +02:00 committed by Austin Horstman
parent 23d85301a5
commit fd22058b43

View file

@ -95,52 +95,51 @@ in
''
);
copyApps = lib.hm.dag.entryAfter [ "installPackages" ] (
let
applications = pkgs.buildEnv {
name = "home-manager-applications";
paths = config.home.packages;
pathsToLink = [ "/Applications" ];
};
in
# bash
''
targetFolder='${cfg.directory}'
# We want to run after linkGeneration so that it will automatically clean
# up the linkApps symlink if it exists so we don't have to implement the
# migration ourselves.
copyApps =
lib.hm.dag.entryAfter
[
"installPackages"
"linkGeneration"
]
(
let
applications = pkgs.buildEnv {
name = "home-manager-applications";
paths = config.home.packages;
pathsToLink = [ "/Applications" ];
};
in
# bash
''
targetFolder='${cfg.directory}'
echo "setting up ~/$targetFolder..." >&2
echo "setting up ~/$targetFolder..." >&2
ourLink () {
local link
link=$(readlink "$1")
[ -L "$1" ] && [ "''${link#*-}" = 'home-manager-applications/Applications' ]
}
run mkdir -p "$targetFolder"
if [ -e "$targetFolder" ] && ourLink "$targetFolder"; then
run rm "$targetFolder"
fi
rsyncFlags=(
# mtime is standardized in the nix store, which would leave only file size to distinguish files.
# Thus we need checksums, despite the speed penalty.
--checksum
# Converts all symlinks pointing outside of the copied tree (thus unsafe) into real files and directories.
# This neatly converts all the symlinks pointing to application bundles in the nix store into
# real directories, without breaking any relative symlinks inside of application bundles.
# This is good enough, because the make-symlinks-relative.sh setup hook converts all $out internal
# symlinks to relative ones.
--copy-unsafe-links
--archive
--delete
--chmod=+w
--no-group
--no-owner
)
run mkdir -p "$targetFolder"
rsyncFlags=(
# mtime is standardized in the nix store, which would leave only file size to distinguish files.
# Thus we need checksums, despite the speed penalty.
--checksum
# Converts all symlinks pointing outside of the copied tree (thus unsafe) into real files and directories.
# This neatly converts all the symlinks pointing to application bundles in the nix store into
# real directories, without breaking any relative symlinks inside of application bundles.
# This is good enough, because the make-symlinks-relative.sh setup hook converts all $out internal
# symlinks to relative ones.
--copy-unsafe-links
--archive
--delete
--chmod=+w
--no-group
--no-owner
)
run ${lib.getExe pkgs.rsync} "''${rsyncFlags[@]}" ${applications}/Applications/ "$targetFolder"
''
);
run ${lib.getExe pkgs.rsync} "''${rsyncFlags[@]}" ${applications}/Applications/ "$targetFolder"
''
);
};
};
}