Skip to content

Instantly share code, notes, and snippets.

@ixxie

ixxie/install.sh Secret

Last active August 26, 2018 12:16
Show Gist options
  • Save ixxie/fda90b1b4e3656f297980e91a883615e to your computer and use it in GitHub Desktop.
Save ixxie/fda90b1b4e3656f297980e91a883615e to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Script to use Clever's kexec method to install NixOS on a Hetzner Cloud VM
TARGET=$1
printf "\n<<Copying kexec tarball to target>>\n"
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
./nix-tests/kexec/result/tarball/nixos-system-x86_64-linux.tar.xz root@${TARGET}:/
printf "\n<<Running kexec on target>>\n"
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
root@${TARGET} "cd / && tar -xf nixos-system-x86_64-linux.tar.xz && ./kexec_nixos"
sleep 32
printf "\n<<Formatting disk & generating configuration>>\n"
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@${TARGET} \
"mkfs.ext4 -F /dev/sda1 && mount /dev/sda1 /mnt && nixos-generate-config --root /mnt"
printf "\n<<Copying temporary configuration to target>>\n"
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
./temp-config.nix root@${TARGET}:/mnt/etc/nixos/configuration.nix
printf "\n<<Installing NixOS>>\n"
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
root@${TARGET} "nixos-install && reboot"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment