diff options
author | Alan Pearce | 2024-05-12 15:53:03 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-18 12:17:12 +0200 |
commit | 312a4ce589f85d955a19b9d86f0c89b930147072 (patch) | |
tree | 0c2b383461dd4fe81f1161dd8b5bf5df4af005a1 /bin | |
parent | cb6c1b4d42c5170ee0d4ac61a75c674777c86b53 (diff) | |
download | nixfiles-312a4ce589f85d955a19b9d86f0c89b930147072.tar.lz nixfiles-312a4ce589f85d955a19b9d86f0c89b930147072.tar.zst nixfiles-312a4ce589f85d955a19b9d86f0c89b930147072.zip |
Revert "pin channels using nix.nixPath rather than using ~/.nix-defexpr"
This reverts commit 4e5e1bca6c94b922e906549683e1780a1d49d02f.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/home-manager | 54 |
1 files changed, 46 insertions, 8 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) |