1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-30 06:59:45 +01:00

files: link home files instead of copying

Only copy files that need their execute bit changed or use the
deprecated `mode` option.
This commit is contained in:
Cornelius Mika 2017-11-06 10:28:50 +01:00 committed by Robert Helgesson
parent b8ddb11796
commit 9627fe6be6
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86

View file

@ -264,35 +264,56 @@ in
home-files = pkgs.stdenv.mkDerivation { home-files = pkgs.stdenv.mkDerivation {
name = "home-manager-files"; name = "home-manager-files";
buildCommand = # Symlink directories and files that have the right execute bit.
"mkdir -p $out\n" + # Copy files that need their execute bit changed or use the
concatStringsSep "\n" ( # deprecated 'mode' option.
mapAttrsToList (n: v: buildCommand = ''
let mkdir -p $out
mode =
if v.mode != null
then v.mode
else
if v.executable != null
then (if v.executable then "+x" else "-x")
else "+r"; # Acts as a no-op.
in ''
target="$(realpath -m "$out/${v.target}")"
# Target file must be within $HOME. function insertFile() {
if [[ ! "$target" =~ "$out" ]] ; then local source="$1"
echo "Error installing file '${v.target}' outside \$HOME" >&2 local relTarget="$2"
local executable="$3"
local mode="$4" # For backwards compatibility.
# Figure out the real absolute path to the target.
local target
target="$(realpath -m "$out/$relTarget")"
# Target path must be within $HOME.
if [[ ! $target =~ $out ]] ; then
echo "Error installing file '$relTarget' outside \$HOME" >&2
exit 1 exit 1
fi fi
if [ -d "${v.source}" ]; then mkdir -p "$(dirname "$target")"
mkdir -p "$(dirname "$out/${v.target}")" if [[ -d $source ]]; then
ln -s "${v.source}" "$target" ln -s "$source" "$target"
elif [[ $mode ]]; then
install -m "$mode" "$source" "$target"
else else
install -D -m${mode} "${v.source}" "$target" [[ -x $source ]] && isExecutable=1 || isExecutable=""
if [[ $executable == symlink || $isExecutable == $executable ]]; then
ln -s "$source" "$target"
else
cp "$source" "$target"
if [[ $executable ]]; then
chmod +x "$target"
else
chmod -x "$target"
fi fi
'' fi
) cfg fi
}
'' + concatStrings (
mapAttrsToList (n: v: ''
insertFile "${v.source}" \
"${v.target}" \
"${if v.executable == null
then "symlink"
else builtins.toString v.executable}" \
"${builtins.toString v.mode}"
'') cfg
); );
}; };
}; };