Install NixOS on Hetzner Cloud: Difference between revisions
Install NixOS on Hetzner Cloud (view source)
Revision as of 23:23, 26 June 2024
, Wednesday at 23:23Not sure why, but color scheme installed via plugin is not really colorful. Probably some terminal / vim color mess-up
Oldhomemovie (talk | contribs) mNo edit summary |
Oldhomemovie (talk | contribs) (Not sure why, but color scheme installed via plugin is not really colorful. Probably some terminal / vim color mess-up) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 28: | Line 28: | ||
</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. '''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]. | </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. '''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]. | ||
#Attach an ISO with NixOS installer. Run:<syntaxhighlight lang="shell"> | #Attach an ISO with NixOS installer. Run:<syntaxhighlight lang="shell"> | ||
hcloud server attach-iso my-hetzner-vm nixos-minimal-24.05.1503.752c634c09ce- | hcloud server attach-iso my-hetzner-vm nixos-minimal-24.05.1503.752c634c09ce-x86_64-linux.iso | ||
</syntaxhighlight>'''Note''': Hetzner attempts to keep the image as up-to-date as possible, hence the hash of the nixos-minimal image at the time of following this tutorial is highly likely to have changed. Run <code>hcloud iso list</code> and look up an up-to-date name of the nixos-minimal ISO image. | </syntaxhighlight>'''Note''': Hetzner attempts to keep the image as up-to-date as possible, hence the hash of the nixos-minimal image at the time of following this tutorial is highly likely to have changed. Run <code>hcloud iso list</code> and look up an up-to-date name of the nixos-minimal ISO image. | ||
#Start a VM. Run:<syntaxhighlight lang="shell"> | #Start a VM. Run:<syntaxhighlight lang="shell"> | ||
Line 35: | Line 35: | ||
#Open Hetzner Cloud console web page, find the <code>my-hetzner-vm</code> server, open a remote web terminal (aka "VNC over "wss://") and change password of <code>nixos</code> user to <code>my-temp-password-123</code>:[[File:Prompt_with_a_token.png|right|frameless|197x197px]] | #Open Hetzner Cloud console web page, find the <code>my-hetzner-vm</code> server, open a remote web terminal (aka "VNC over "wss://") and change password of <code>nixos</code> user to <code>my-temp-password-123</code>:[[File:Prompt_with_a_token.png|right|frameless|197x197px]] | ||
# 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- | mkdir -p /tmp/my-first-flake/my-vms/my-hetzner-vm/ | ||
</syntaxhighlight> | </syntaxhighlight> | ||
#Using a code editor on your host computer, create 4 files. File contents, as well as the location of where to put corresponding file are indicated below:<syntaxhighlight lang="nix"> | #Using a code editor on your host computer, create 4 files. File contents, as well as the location of where to put corresponding file are indicated below:<syntaxhighlight lang="nix"> | ||
# /tmp/my-first-flake/my- | # /tmp/my-first-flake/my-vms/my-hetzner-vm/hardware-configuration.nix | ||
{ config, lib, pkgs, modulesPath, ... }: | { config, lib, pkgs, modulesPath, ... }: | ||
Line 56: | Line 56: | ||
} | } | ||
</syntaxhighlight><syntaxhighlight lang="nix"> | </syntaxhighlight><syntaxhighlight lang="nix"> | ||
# /tmp/my-first-flake/my- | # /tmp/my-first-flake/my-vms/my-hetzner-vm/disko-config.nix | ||
{ | { | ||
Line 96: | Line 96: | ||
} | } | ||
</syntaxhighlight><syntaxhighlight lang="nix"> | </syntaxhighlight><syntaxhighlight lang="nix"> | ||
# /tmp/my-first-flake/my- | # /tmp/my-first-flake/my-vms/my-hetzner-vm/configuration.nix | ||
{ config, lib, pkgs, ... }: | { config, lib, pkgs, ... }: | ||
Line 122: | Line 122: | ||
configure = { | configure = { | ||
customRC = '' | customRC = '' | ||
colorscheme | colorscheme habamax | ||
''; | ''; | ||
packages.packages = { | packages.packages = { | ||
start = [ | start = [ | ||
pkgs.vimPlugins. | pkgs.vimPlugins.nerdtree | ||
]; | ]; | ||
}; | }; | ||
Line 160: | Line 160: | ||
modules = [ | modules = [ | ||
./my- | ./my-vms/my-hetzner-vm/configuration.nix | ||
inputs.disko.nixosModules.disko | inputs.disko.nixosModules.disko | ||
]; | ]; | ||
Line 182: | Line 182: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The NixOS on Hetzner is installed! Let's do a few more steps to customize the installation. | 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:~/ | ||
</syntaxhighlight> | </syntaxhighlight>'''Note''': again, replace <code>0.0.0.0</code> with an IP address obtained via <code>hcloud server ip my-hetzner-vm</code>. | ||
#Using <code>neovim</code> editor on the VM, modify <code>configuration.nix</code> to include a package containing Elixir programming language runtime for <code>eugene</code> user. Run:<syntaxhighlight lang="shell"> | #Using <code>neovim</code> editor on the VM, modify <code>configuration.nix</code> to include a package containing Elixir programming language runtime for <code>eugene</code> user. Run:<syntaxhighlight lang="shell"> | ||
nvim my-first-flake/my-vms/my-hetzner-vm/configuration.nix | nvim my-first-flake/my-vms/my-hetzner-vm/configuration.nix |