diff --git a/nixos-infect b/nixos-infect index fc01455..f2acad3 100755 --- a/nixos-infect +++ b/nixos-infect @@ -13,10 +13,10 @@ # systems. # # WARNING NB This script wipes out the targeted host's root filesystem when it -# runs to completion. Any errors halt execution. set -x is used to help debug, -# as often a failed run leaves the system in an inconsistent state, requiring a -# rebuild (in DigitalOcean panel: Droplet Settings -> "Destroy" -> "Rebuild -# from original"). +# runs to completion. Any errors halt execution. It's advised to run with +# `bash -x` to help debug, as often a failed run leaves the system in an +# inconsistent state, requiring a rebuild (in DigitalOcean panel: Droplet +# Settings -> "Destroy" -> "Rebuild from original"). # # TO USE: # - Add any custom config you want (see notes below) @@ -45,9 +45,11 @@ # simply didn't work for me! (old system was being because grub wasnt properly # reinstalled) -set -ex -o pipefail +set -e -o pipefail makeConf() { + # Skip everything if main config already present + [[ -e /etc/nixos/configuration.nix ]] && return 0 # NB <<"EOF" quotes / $ ` in heredocs, <> /etc/NIXOS_LUSTRATE echo root/.nix-defexpr/channels >> /etc/NIXOS_LUSTRATE - rm -rf /boot.bak && mv -v /boot /boot.bak && \ - /nix/var/nix/profiles/system/bin/switch-to-configuration boot + rm -rf /boot.bak + mv -v /boot /boot.bak + /nix/var/nix/profiles/system/bin/switch-to-configuration boot } prepareEnv