Last active
July 21, 2020 15:43
-
-
Save sputn1ck/7a8d5ca479e6a6a3000ecaa6388de204 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
# Script to install NixOS from the Hetzner Cloud NixOS bootable ISO image. | |
# Wipes the disk! | |
# Tested with Hetzner's `NixOS 20.03 (amd64/minimal)` ISO image. | |
# | |
# Run like: | |
# | |
# curl https://nh2.me/nixos-install-hetzner-cloud.sh | sudo bash | |
# | |
# To run it from the Hetzner Cloud web terminal without typing it down, | |
# use `xdotoool` (you have e.g. 3 seconds to focus the window): | |
# | |
# sleep 3 && xdotool type --delay 50 'curl https://nh2.me/nixos-install-hetzner-cloud.sh | sudo bash' | |
# | |
# (In the xdotool invocation you may have to replace chars so that | |
# the right chars appear on the US-English keyboard.) | |
# | |
# If you want to be able to SSH straight in, | |
# do not forget to replace the SSH key below by yours | |
# (in the section labelled "Replace this by your SSH pubkey"), | |
# and host script modified this way under and URL of your choosing. | |
# Otherwise you'l be running with my pubkey, but you can change it | |
# afterwards by logging in via the Hetzner Cloud web terminal as `root` | |
# with empty password. | |
set -e | |
mkfs.ext4 /dev/sda1 | |
mount /dev/sda1 /mnt | |
nixos-generate-config --root /mnt | |
# Delete trailing `}` from `configuration.nix` so that we can append more to it. | |
sed -i -E 's:^\}\s*$::g' /mnt/etc/nixos/configuration.nix | |
# Extend/override default `configuration.nix`: | |
echo ' | |
boot.loader.grub.devices = [ "/dev/sda" ]; | |
# Initial empty root password for easy login: | |
users.users.root.initialHashedPassword = ""; | |
services.openssh.permitRootLogin = "prohibit-password"; | |
services.openssh.enable = true; | |
# Replace this by your SSH pubkey | |
users.users.root.openssh.authorizedKeys.keys = [ | |
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDbp4Vz41jtHxk5ZVaAlv4S1Be2AcKDOU98T8EAjPPHMNQT9PbtvgPrPcXxlcUZj3CIfL0deyG579UhGPRqcOYDw0sDiZh4KLhlZb0q9xJDyhvRnSPsOUZrIhc/8eDlQcs1wGcZiEz63Yi0qREPWwnUEYmKFpSsf50Q2mNimQTiN+LahP5lYyPys4dbuuOtXl44mFOv45WUXaDIPd2xZwemXc3zkfPUU5XKeMEqMWU/6QQ5WIeNgsGhNyBzuuVISS+FsM6xbqLGZ+X/U6KVwDtUhVVtT83hEug1rT/Gwt5KaUbZrAcvOp9YE30mafUz6MsyS5BRVnNbIsvvV34v8IE7 kon@DESKTOP-NEGHQ8E" | |
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJmJ9/NXh4HkJiB3jLEWLWrYpStOi7lYsLgpwEkB1sOK kon@Konstantins-MBP.fritz.box" | |
]; | |
} | |
' >> /mnt/etc/nixos/configuration.nix | |
nixos-install --no-root-passwd | |
reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment