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:
parent
40005d0e88
commit
87b24626ea
33
bin/hey
33
bin/hey
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue