1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-04 18:29:45 +01:00

files: support recursive linking of directory

This commit is contained in:
Robert Helgesson 2017-11-06 18:00:25 +01:00
parent fad1e108d8
commit 54043df8fb
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86
2 changed files with 28 additions and 2 deletions

View file

@ -186,6 +186,8 @@ in
home-files = pkgs.stdenv.mkDerivation { home-files = pkgs.stdenv.mkDerivation {
name = "home-manager-files"; name = "home-manager-files";
nativeBuildInputs = [ pkgs.xlibs.lndir ];
# Symlink directories and files that have the right execute bit. # Symlink directories and files that have the right execute bit.
# Copy files that need their execute bit changed or use the # Copy files that need their execute bit changed or use the
# deprecated 'mode' option. # deprecated 'mode' option.
@ -197,6 +199,7 @@ in
local relTarget="$2" local relTarget="$2"
local executable="$3" local executable="$3"
local mode="$4" # For backwards compatibility. local mode="$4" # For backwards compatibility.
local recursive="$5"
# Figure out the real absolute path to the target. # Figure out the real absolute path to the target.
local target local target
@ -210,7 +213,12 @@ in
mkdir -p "$(dirname "$target")" mkdir -p "$(dirname "$target")"
if [[ -d $source ]]; then if [[ -d $source ]]; then
ln -s "$source" "$target" if [[ $recursive ]]; then
mkdir -p "$target"
lndir -silent "$source" "$target"
else
ln -s "$source" "$target"
fi
elif [[ $mode ]]; then elif [[ $mode ]]; then
install -m "$mode" "$source" "$target" install -m "$mode" "$source" "$target"
else else
@ -234,7 +242,8 @@ in
"${if v.executable == null "${if v.executable == null
then "symlink" then "symlink"
else builtins.toString v.executable}" \ else builtins.toString v.executable}" \
"${builtins.toString v.mode}" "${builtins.toString v.mode}" \
"${builtins.toString v.recursive}"
'') cfg '') cfg
); );
}; };

View file

@ -89,6 +89,23 @@ in
for files created through the <varname>text</varname> option. for files created through the <varname>text</varname> option.
''; '';
}; };
recursive = mkOption {
type = types.bool;
default = false;
description = ''
If the file source is a directory, then this option
determines whether the directory should be recursively
linked to the target location. This option has no effect
if the source is a file.
</para><para>
If <literal>false</literal> (the default) then the target
will be a symbolic link to the source directory. If
<literal>true</literal> then the target will be a
directory structure matching the source's but whose leafs
are symbolic links to the files of the source directory.
'';
};
}; };
config = { config = {