Add 'hey swap'

For swapping out symlinked store files so I can tweak them without
doing a complete rebuild each time.
This commit is contained in:
Henrik Lissner 2020-10-17 16:48:08 -04:00
parent 40005d0e88
commit 87b24626ea
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

33
bin/hey
View file

@ -45,6 +45,7 @@ function main {
echo " vm TODO" echo " vm TODO"
echo " push Push thie config to a remote NixOS system and rebuild it" echo " push Push thie config to a remote NixOS system and rebuild it"
echo " generations (gen) TODO" echo " generations (gen) TODO"
echo " swap TODO"
} }
function _rebuild { function _rebuild {
@ -76,6 +77,38 @@ function main {
fi fi
} }
function _swap {
for target in $@; do
if [ -d "$target" ]; then
files=( "$target"/**/*.nix-store-backup )
links=( $(find "$target" -type l) )
if [[ "$files" ]]; then
echo "There are swapped files here. Unswapping!"
for file in $files[@]; do
_swap "$link"
done
else
echo "Swapping files in $target"
for link in $links[@]; do
if [[ "$(readlink $link)" == /nix/store/* ]]; then
_swap "$link"
fi
done
fi
elif [ -f "$target.nix-store-backup" ]; then
echo "Unswapping $target"
_do mv -i "$target.nix-store-backup" "$target"
elif [ -f "$target" ]; then
echo "Swapping $target"
_do mv "$target" "$target.nix-store-backup"
_do cp "$target.nix-store-backup" "$target"
else
>&2 echo "Not a valid target: $target"
exit 1
fi
done
}
### ###
cmd="$1" cmd="$1"
[[ $# > 0 ]] && shift [[ $# > 0 ]] && shift