Install NixOS on Hetzner Cloud: Difference between revisions
Oldhomemovie (talk | contribs) mNo edit summary |
Oldhomemovie (talk | contribs) No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 9: | Line 9: | ||
There are several ways to install NixOS, such as the "traditional" ISO installation, [[nixos-infect]] or [[nixos-anywhere]]. | There are several ways to install NixOS, such as the "traditional" ISO installation, [[nixos-infect]] or [[nixos-anywhere]]. | ||
=== | === Tradition ISO installation === | ||
TODO | |||
=== nixos-anywhere === | |||
The tutorial assumes you already have an account on Hetzner Cloud, and no prior access to a system with NixOS or nix CLI utility installed: | The tutorial assumes you already have an account on Hetzner Cloud, and no prior access to a system with NixOS or nix CLI utility installed: | ||
# Create a temp folder for future use. Run:<syntaxhighlight lang="shell"> | # Create a temp folder for future use. Run:<syntaxhighlight lang="shell"> | ||
Line 18: | Line 21: | ||
</syntaxhighlight>'''Note''': this is done in a container in order to reduce the "setup footprint and residue", allowing to throw away this setup environment quickly. | </syntaxhighlight>'''Note''': this is done in a container in order to reduce the "setup footprint and residue", allowing to throw away this setup environment quickly. | ||
#Install <code>nix</code> and <code>hcloud</code> CLI utilities. Run:<syntaxhighlight lang="shell"> | #Install <code>nix</code> and <code>hcloud</code> CLI utilities. Run:<syntaxhighlight lang="shell"> | ||
apk add nix hcloud | apk add nix hcloud | ||
</syntaxhighlight> | </syntaxhighlight> | ||
#Authenticate <code>hcloud</code> CLI utility. Run:<syntaxhighlight lang="shell"> | #Authenticate <code>hcloud</code> CLI utility. Run:<syntaxhighlight lang="shell"> | ||
Line 25: | Line 28: | ||
#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 108: | ||
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 122: | Line 123: | ||
configure = { | configure = { | ||
customRC = '' | customRC = '' | ||
colorscheme | colorscheme habamax | ||
''; | ''; | ||
packages.packages = { | packages.packages = { | ||
start = [ | start = [ | ||
pkgs.vimPlugins. | pkgs.vimPlugins.nerdtree | ||
]; | ]; | ||
}; | }; | ||
Line 168: | Line 169: | ||
} | } | ||
</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. | ||
The NixOS on Hetzner is installed! | |||
Let's do a few more steps to customize the installation. | |||
#Copy flake files onto the server. Run:<syntaxhighlight lang="shell"> | #Copy flake files onto the server. Run:<syntaxhighlight lang="shell"> | ||
scp -r /tmp/my-first-flake eugene@0.0.0.0:~/ | scp -r /tmp/my-first-flake eugene@0.0.0.0:~/ |