1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-27 12:19:48 +01:00

home-environment: fail if a home.file is outside $HOME

This commit is contained in:
Robert Helgesson 2017-09-13 15:19:49 +02:00
parent aa69598b57
commit 6ecf9e091c
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86

View file

@ -416,11 +416,19 @@ in
concatStringsSep "\n" (
mapAttrsToList (n: v:
''
target="$(realpath -m "$out/${v.target}")"
# Target file must be within $HOME.
if [[ ! "$target" =~ "$out" ]] ; then
echo "Error installing file '${v.target}' outside \$HOME" >&2
exit 1
fi
if [ -d "${v.source}" ]; then
mkdir -pv "$(dirname "$out/${v.target}")"
ln -sv "${v.source}" "$out/${v.target}"
ln -sv "${v.source}" "$target"
else
install -D -m${v.mode} "${v.source}" "$out/${v.target}"
install -D -m${v.mode} "${v.source}" "$target"
fi
''
) cfg.file