Install NixOS on Hetzner Cloud: Difference between revisions
Oldhomemovie (talk | contribs) Not sure why, but color scheme installed via plugin is not really colorful. Probably some terminal / vim color mess-up |
Oldhomemovie (talk | contribs) Re-work tutorial to rely on the kexec method |
||
Line 25: | Line 25: | ||
#When asked, enter value of the token in the prompt. '''Note''': the token with "Read/Write" permissions can be obtained on a project page inside Hetzner Cloud: <nowiki>https://console.hetzner.cloud/projects/0000000/security/tokens</nowiki> | #When asked, enter value of the token in the prompt. '''Note''': the token with "Read/Write" permissions can be obtained on a project page inside Hetzner Cloud: <nowiki>https://console.hetzner.cloud/projects/0000000/security/tokens</nowiki> | ||
#Create a VM on Hetzner. Run:<syntaxhighlight lang="shell"> | #Create a VM on Hetzner. Run:<syntaxhighlight lang="shell"> | ||
hcloud server create --name my-hetzner-vm --type cpx21 --image ubuntu-24.04 --location fsn1 | hcloud server create --name my-hetzner-vm --type cpx21 --image ubuntu-24.04 --location fsn1 | ||
</syntaxhighlight>'''Note 1''': this tutorial uses <code>cpx21</code> VM instance type which corresponds to an x86 architecture marchine with 3 CPU cores and 4GB of RAM, and <code>fsn1</code> location which corresponds to a data center in the city of Falkenstein in Germany. A list of all instance types can be obtained by running command <code>hcloud server-type list</code>, while a list of all locations can be obtained by running <code>hcloud location list</code> command. | </syntaxhighlight>Write down IP and generated user password. '''Note 1''': this tutorial uses <code>cpx21</code> VM instance type which corresponds to an x86 architecture marchine with 3 CPU cores and 4GB of RAM, and <code>fsn1</code> location which corresponds to a data center in the city of Falkenstein in Germany. A list of all instance types can be obtained by running command <code>hcloud server-type list</code>, while a list of all locations can be obtained by running <code>hcloud location list</code> command. '''Note 2''': Hopefully, Hetzner Cloud team will support NixOS disk images soon, see [https://www.reddit.com/r/NixOS/comments/1desdbv/could_we_convince_hetzner_to_add_nixos_as_a/ Could we convince Hetzner to add Nixos as a standard image choice]. | ||
# | #SSH onto the server using IP and root password obtained after the previous step:<syntaxhighlight lang="shell"> | ||
ssh root@0.0.0.0 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
# | #Change the password to something temporal, for example: <code>my-temp-password-123</code>. | ||
# On your host computer, create a folder. Run:<syntaxhighlight lang="shell"> | # On your host computer, create a folder. Run:<syntaxhighlight lang="shell"> | ||
mkdir -p /tmp/my-first-flake/my-vms/my-hetzner-vm/ | mkdir -p /tmp/my-first-flake/my-vms/my-hetzner-vm/ | ||
Line 108: | Line 105: | ||
boot.loader.grub.enable = true; | boot.loader.grub.enable = true; | ||
boot.loader.grub.device = "/dev/sda1"; | |||
services.openssh.enable = true; | services.openssh.enable = true; | ||
Line 168: | Line 166: | ||
} | } | ||
</syntaxhighlight>'''Note''': all these files constitute what's known as a ''nix [[flake]]''. The flake in question is small, though not exactly a minimal one. | </syntaxhighlight>'''Note''': all these files constitute what's known as a ''nix [[flake]]''. The flake in question is small, though not exactly a minimal one. | ||
#Build NixOS from flake. Run:<syntaxhighlight lang="shell"> | #Build NixOS from flake. Run:<syntaxhighlight lang="shell"> | ||
nix run --extra-experimental-features 'nix-command flakes' github:nix-community/nixos-anywhere -- --flake /tmp/my-first-flake#my-hetzner-vm nixos@0.0.0.0 --build-on-remote | nix run --extra-experimental-features 'nix-command flakes' github:nix-community/nixos-anywhere -- --flake /tmp/my-first-flake#my-hetzner-vm nixos@0.0.0.0 --build-on-remote | ||
</syntaxhighlight>'''Note''': replace <code>0.0.0.0</code> with an IP address obtained during | </syntaxhighlight>'''Note''': replace <code>0.0.0.0</code> with an IP address obtained during an earlier step. | ||
#Detach ISO from VM. Run:<syntaxhighlight lang="shell"> | #Detach ISO from VM. Run:<syntaxhighlight lang="shell"> | ||
hcloud server detach-iso my-hetzner-vm | hcloud server detach-iso my-hetzner-vm |