diff options
-rwxr-xr-x | bin/home-manager | 54 | ||||
-rw-r--r-- | lib/default.nix | 2 |
2 files changed, 47 insertions, 9 deletions
diff --git a/bin/home-manager b/bin/home-manager index 70ef9064..5e10bc77 100755 --- a/bin/home-manager +++ b/bin/home-manager @@ -31,13 +31,40 @@ for i in 1 echo "user home-manager configuration folder $hm_config_dir does not exist, creating it" mkdir -p $hm_config_dir end - if test -e $channel_root - if test ! -L $channel_root - rm $channel_root/* || exit 1 - rmdir $channel_root + if test ! -e $channel_root + if test -L $channel_root + # broken symlink + rm $channel_root + end + echo "channel root $channel_root does not exist, creating it" + mkdir -p $channel_root + else + if test ! -d $channel_root + echo "error: $channel_root is not a directory" + else if test -L $channel_root + echo "error: $channel_root is a symlink, please remove it" + else if path is --invert --perm write $channel_root + echo "error: $channel_root is not writable; might be a symlink" + else if path is --invert --type link $channel_root/* + for p in (path filter --invert --type link $channel_root/*) + # might be a broken symlink + if test -L $p -a ! -e $p + rm $p + else + echo "error: channel $p is not a broken symlink, don't know what to do with it" + end + end + # check again and fail if there are still unknown files + if path is --invert --type link $channel_root/* + echo "error: non-link(s) in $channel_root" + path filter --invert --type link $channel_root/* + else + continue + end else - rm $channel_root || exit 1 + continue # with script end + exit 1 end end @@ -69,6 +96,8 @@ switch $current_script_name set --export HOME_MANAGER_CONFIG $hm_config_source end +set --function old_channels (path basename $channel_root/*) + function update_link --argument-names new_src target set --function current_src (path resolve $target) if test -e $current_src @@ -83,12 +112,21 @@ function update_link --argument-names new_src target end for np in $NIX_PATH - echo $np | read --function --delimiter "=" channel new_src + echo $np | read --function --delimiter "=" channel new_src_rel + set --local new_src (path resolve $new_src_rel) - if test $channel = nixpkgs-overlays - update_link $new_src $user_nixpkgs/overlays + if test $channel = darwin-config continue end + if set --local i (contains --index $channel $old_channels) + set --erase old_channels[$i] + end + + update_link $new_src $channel_root/$channel +end + +for old in $channel_root/$old_channels + rm $old end set --function i (contains --index (status dirname) $PATH) diff --git a/lib/default.nix b/lib/default.nix index 023566e5..93f64059 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -10,7 +10,7 @@ rec { if s.type == "local" then - toString (lib.path.append ../. s.outPath) + lib.path.append ../. s.outPath else toString s.outPath ; |