From 87b24626eaf359f7a303a72bc52b96f07230cf4c Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 17 Oct 2020 16:48:08 -0400 Subject: [PATCH] Add 'hey swap' For swapping out symlinked store files so I can tweak them without doing a complete rebuild each time. --- bin/hey | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/bin/hey b/bin/hey index 614b37b3..46fab8cf 100755 --- a/bin/hey +++ b/bin/hey @@ -45,6 +45,7 @@ function main { echo " vm TODO" echo " push Push thie config to a remote NixOS system and rebuild it" echo " generations (gen) TODO" + echo " swap TODO" } function _rebuild { @@ -76,6 +77,38 @@ function main { 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" [[ $# > 0 ]] && shift