diff --git a/nixos-infect b/nixos-infect index 4ef674a..108eb1a 100755 --- a/nixos-infect +++ b/nixos-infect @@ -1,6 +1,6 @@ #! /usr/bin/env bash -# Use Digital Ocean Droplet image: +# These are the only supported Digital Ocean images: # # Fedora 24 x64 # Ubuntu 16.04 x64 @@ -45,10 +45,7 @@ # simply didn't work for me! (old system was being because grub wasnt properly # reinstalled) -set -ex - -export disk=$( (>/dev/null ls -l /dev/vda && echo vda) \ - || (>/dev/null ls -l /dev/sda && echo sda) ) +set -ex -o pipefail makeConf() { # NB <<"EOF" quotes / $ ` in heredocs, <' \ - -p /nix/var/nix/profiles/system \ - -A system + [ -z "$NIX_CHANNEL"] && NIX_CHANNEL="nixos-16.09" + nix-channel --remove nixpkgs + nix-channel --add "https://nixos.org/channels/$NIX_CHANNEL" nixos + nix-channel --update -# Remove nix installed with curl | bash -rm -fv /nix/var/nix/profiles/default* -/nix/var/nix/profiles/system/sw/bin/nix-collect-garbage + export NIXOS_CONFIG=/etc/nixos/configuration.nix -# Follow the symlinks -[ -L /etc/resolv.conf ] && mv -v /etc/resolv.conf /etc/resolv.conf.lnk && cat /etc/resolv.conf.lnk > /etc/resolv.conf + nix-env --set \ + -I nixpkgs=$HOME/.nix-defexpr/channels/nixos \ + -f '' \ + -p /nix/var/nix/profiles/system \ + -A system -# Staging for the Nix coup d'état -touch /etc/NIXOS -cat > /etc/NIXOS_LUSTRATE << EOF -etc/nixos -etc/resolv.conf -root/.nix-defexpr/channels -EOF + # Remove nix installed with curl | bash + rm -fv /nix/var/nix/profiles/default* + /nix/var/nix/profiles/system/sw/bin/nix-collect-garbage -rm -rf /boot.bak && mv -v /boot /boot.bak && - /nix/var/nix/profiles/system/bin/switch-to-configuration boot + # Follow the symlinks + [ -L /etc/resolv.conf ] && mv -v /etc/resolv.conf /etc/resolv.conf.lnk && cat /etc/resolv.conf.lnk > /etc/resolv.conf -reboot + # Staging for the Nix coup d'état + touch /etc/NIXOS + cat > /etc/NIXOS_LUSTRATE << EOF + etc/nixos + etc/resolv.conf + root/.nix-defexpr/channels + EOF + + rm -rf /boot.bak && mv -v /boot /boot.bak && + /nix/var/nix/profiles/system/bin/switch-to-configuration boot +} + +prepareEnv +checkEnv && infect && reboot