Install NixOS on Hetzner Online: Difference between revisions
imported>Montchr m Bash syntax highlighting for nixos-generators section |
imported>Montchr Use simplified Nix installation instructions from nixos-install-scripts |
||
Line 77: | Line 77: | ||
== Bootstrap from the Rescue System == | == Bootstrap from the Rescue System == | ||
Here are some quick notes on how to bootstrap. | Here are some quick notes on how to bootstrap. | ||
The nixos-install-scripts repo may also be a valuable resource: | |||
https://github.com/nix-community/nixos-install-scripts/tree/master/hosters/hetzner-dedicated | |||
Otherwise, inspiration for the kexec approach below comes from https://github.com/ofborg/infrastructure/commit/0712a5cf871b7a6d2fbbd2df539d3cd90ab8fa1f | |||
and https://github.com/andir/infra/tree/master/bootstrap | and https://github.com/andir/infra/tree/master/bootstrap | ||
The main principle is that we will go from: Rescue system, kexec into a NixOS system, finally install the system. | The main principle is that we will go from: Rescue system, install Nix, kexec into a NixOS system, finally install the system. | ||
First, reboot the machine in Rescue mode. Make sure to select your SSH public key. SSH into the machine: | First, reboot the machine in Rescue mode. Make sure to select your SSH public key. SSH into the machine: | ||
<syntaxHighlight lang=bash> | <syntaxHighlight lang=bash> | ||
# | # Let root run the nix installer | ||
mkdir -p /etc/nix | |||
echo "build-users-group =" > /etc/nix/nix.conf | echo "build-users-group =" > /etc/nix/nix.conf | ||
# Install Nix | # Install Nix in single-user mode | ||
curl -L https://nixos.org/nix/install | sh | |||
. $HOME/.nix-profile/etc/profile.d/nix.sh | |||
# Install nixos-generators | # Install nixos-generators | ||
# This might take a while, so the verbose flag `-v` is included to monitor progress | # This might take a while, so the verbose flag `-v` is included to monitor progress | ||
nix-env -f https://github.com/nix-community/nixos-generators/archive/master.tar.gz -i -v | nix-env -f https://github.com/nix-community/nixos-generators/archive/master.tar.gz -i -v | ||
# Create a initial config, just to kexec into | # Create a initial config, just to kexec into | ||
cat <<EOF > / | cat <<EOF > /root/config.nix | ||
{ | { | ||
services.openssh.enable = true; | services.openssh.enable = true; | ||
users.users.root.openssh.authorizedKeys.keys = [ | users.users.root.openssh.authorizedKeys.keys = [ | ||
# Replace with your public key | # Replace with your public key | ||
"ssh-rsa | "ssh-rsa AAAA..." | ||
]; | ]; | ||
} | } | ||
Line 122: | Line 115: | ||
# Generate the kexec script | # Generate the kexec script | ||
nixos-generate -o / | nixos-generate -o /root/result -f kexec-bundle -c /root/config.nix | ||
# Switch to the new system | # Switch to the new system | ||
/ | /root/result | ||
</syntaxHighlight> | </syntaxHighlight> | ||