From d6d5895893627c4972d15a44f993bcddb27f4c5c Mon Sep 17 00:00:00 2001 From: Cornelius Mika Date: Wed, 6 Sep 2017 10:17:31 +0200 Subject: [PATCH] home-environment: link home files instead of copying --- modules/home-environment.nix | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/modules/home-environment.nix b/modules/home-environment.nix index ee2b9c42..d810685a 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -407,6 +407,34 @@ in ${activationCmds} ''; + # Make file that gets linked into $HOME. + # Copy the file if it doesn't have the required execute permissions, + # otherwise link to it. + makeHomeFile = file: + if file.text != null then + # File was created internally and already has the right execute bit. + file.source + else + pkgs.stdenv.mkDerivation { + name = "home-file"; + + inherit (file) source executable; + + buildCommand = '' + if [[ -d $source ]]; then + ln -s $source $out + else + [[ -x $source ]] && isExecutable=1 || isExecutable="" + if [[ $isExecutable == executable ]]; then + ln $source $out + else + cp $source $out + chmod ${if file.executable then "+x" else "-x"} $out + fi + fi + ''; + }; + home-files = pkgs.stdenv.mkDerivation { name = "home-manager-files"; @@ -415,12 +443,8 @@ in concatStringsSep "\n" ( mapAttrsToList (n: v: '' - if [ -d "${v.source}" ]; then - mkdir -pv "$(dirname "$out/${v.target}")" - ln -sv "${v.source}" "$out/${v.target}" - else - install -D -m${if v.executable then "+x" else "-x"} "${v.source}" "$out/${v.target}" - fi + mkdir -p "$(dirname "$out/${v.target}")" + ln -s $(realpath ${makeHomeFile v}) "$out/${v.target}" '' ) cfg.file );