From cad9b43b699d7c2cef8522fbcedd1d0562c5a8e7 Mon Sep 17 00:00:00 2001 From: Eric Litak Date: Mon, 13 Feb 2017 17:30:42 -0800 Subject: [PATCH] prepareEnv,checkEnv refactor; other tiny fixes --- nixos-infect | 99 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 41 deletions(-) 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