home-environment: allow directory as home file

Fixes issue #5.
This commit is contained in:
Robert Helgesson 2017-03-10 23:56:43 +01:00
parent ee9bc66f69
commit 207c349825
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86

View file

@ -115,9 +115,11 @@ in
source = mkOption { source = mkOption {
type = types.path; type = types.path;
description = '' description = ''
Path of the source file. Note, the file name must not Path of the source file. The file name must not start
start with a period since Nix will not allow such with a period since Nix will not allow such names in
names in the Nix store. the Nix store.
</para><para>
This may refer to a directory.
''; '';
}; };
@ -245,10 +247,10 @@ in
newGenFiles="$1" newGenFiles="$1"
shift shift
for sourcePath in "$@" ; do for sourcePath in "$@" ; do
relativePath="$(realpath --relative-to "$newGenFiles" "$sourcePath")" relativePath="''${sourcePath#$newGenFiles/}"
targetPath="$HOME/$relativePath" targetPath="$HOME/$relativePath"
$DRY_RUN_CMD mkdir -p $VERBOSE_ARG "$(dirname "$targetPath")" $DRY_RUN_CMD mkdir -p $VERBOSE_ARG "$(dirname "$targetPath")"
$DRY_RUN_CMD ln -sf $VERBOSE_ARG "$sourcePath" "$targetPath" $DRY_RUN_CMD ln -nsf $VERBOSE_ARG "$sourcePath" "$targetPath"
done done
''; '';
@ -257,9 +259,9 @@ in
oldGenFiles="$2" oldGenFiles="$2"
shift 2 shift 2
for sourcePath in "$@" ; do for sourcePath in "$@" ; do
relativePath="$(realpath --relative-to "$oldGenFiles" "$sourcePath")" relativePath="''${sourcePath#$oldGenFiles/}"
targetPath="$HOME/$relativePath" targetPath="$HOME/$relativePath"
if [[ -f "$newGenFiles/$relativePath" ]] ; then if [[ -e "$newGenFiles/$relativePath" ]] ; then
$VERBOSE_ECHO "Checking $targetPath exists" $VERBOSE_ECHO "Checking $targetPath exists"
else else
echo "Checking $targetPath gone (deleting)" echo "Checking $targetPath gone (deleting)"
@ -274,7 +276,7 @@ in
function linkNewGen() { function linkNewGen() {
local newGenFiles local newGenFiles
newGenFiles="$(readlink -e "$newGenPath/home-files")" newGenFiles="$(readlink -e "$newGenPath/home-files")"
find "$newGenFiles" -type f -print0 \ find "$newGenFiles" -type f -print0 -or -type l -print0 \
| xargs -0 bash ${link} "$newGenFiles" | xargs -0 bash ${link} "$newGenFiles"
} }
@ -288,7 +290,7 @@ in
local newGenFiles oldGenFiles local newGenFiles oldGenFiles
newGenFiles="$(readlink -e "$newGenPath/home-files")" newGenFiles="$(readlink -e "$newGenPath/home-files")"
oldGenFiles="$(readlink -e "$oldGenPath/home-files")" oldGenFiles="$(readlink -e "$oldGenPath/home-files")"
find "$oldGenFiles" -type f -print0 \ find "$oldGenFiles" -type f -print0 -or -type l -print0 \
| xargs -0 bash ${cleanup} "$newGenFiles" "$oldGenFiles" | xargs -0 bash ${cleanup} "$newGenFiles" "$oldGenFiles"
} }
@ -341,8 +343,15 @@ in
installPhase = installPhase =
"mkdir -p $out\n" + "mkdir -p $out\n" +
concatStringsSep "\n" ( concatStringsSep "\n" (
mapAttrsToList (name: value: mapAttrsToList (n: v:
"install -D -m${value.mode} ${value.source} $out/${value.target}" ''
if [ -d "${v.source}" ]; then
mkdir -pv "$(dirname "$out/${v.target}")"
ln -sv "${v.source}" "$out/${v.target}"
else
install -D -m${v.mode} "${v.source}" "$out/${v.target}"
fi
''
) cfg.file ) cfg.file
); );
}; };