This is the gist of how to setup a NixOS server on a Hetzner Cloud instance with an admin user, ssh access and configuration management via git.
- Create a Hetzner Cloud instance and click to enter it.
- Stop the instance (top right corner icon).
- Go to ISO Images.
- Search for "nixos" and click mount.

- Start the instance again (top right corner icon).
- Open the console (top right corner icon).
- Get the IP address by executing
ip --brief --color address. The address can also be optained from the Hetzner Cloud web interface.
lo UNKNOWN 127.0.0.1/8 ::1/128
enp61s0 UP <IPv4 address>/24 <IPv6 address>/64
- Download your public ssh key to the machine. If you have a GitHub account you can download it from there.
mkdir ~/.ssh
curl -L https://github.com/<username>.keys | tee -a .ssh/authorized_keys
- Log on from your computer on via ssh.
ssh nixos@<IPv4 address>
- Partition, format and mountthe disk.
sudo -i
parted /dev/sda -- mklabel msdos
parted /dev/sda -- mkpart primary 1MiB 100%
partprobe
mkfs.ext4 -L nixos /dev/sda1
mount /dev/disk/by-label/nixos /mnt
- Generate the initial configuration and install.
nixos-generate-config --root /mnt
sed -e 's/^.*boot\.\.grub\.device.*$/ boot..grub.device = "\/dev\/sda";/g' -i /mnt/etc/nixos/configuration.nix
mkdir /mnt/etc/nixos/configuration/
sed -e 's/\.\/hardware-configuration\.nix/.\/hardware-configuration.nix\n .\/configuration/g' -i /mnt/etc/nixos/configuration.nix
- Open
/mnt/etc/nixos/configuration/default.nixwith an editor likevimornanoand paste the following.
{ config, pkgs, ... }:
{
imports =
[
./user.nix
];
environment.systemPackages = with pkgs; [
vim
wget
git
htop bottom
];
services.openssh.enable = true;
}
- Open
/mnt/etc/nixos/configuration/user.nixwith an editor and paste the following to create an account with the name admin. Replace the public ssh key with yours.
{ config, pkgs, ... }:
{
imports = [
];
users = {
users = {
admin = {
isNormalUser = true;
extraGroups = [ "wheel" ];
initialHashedPassword = "";
openssh.authorizedKeys.keys = [ "ssh-ed25519 AAAA...." ];
};
};
};
}
- Perform installation.
nixos-install --no-root-passwd
- Enter the mounted installation and set a password for the admin account.
nixos-enter --root /mnt
passwd admin
exit
- Shut down the machine.
poweroff
- Unmount the ISO in the Hetzner Cloud interface and start the machine again.
- Log on via SSH.
ssh-keygen -R <IPv4 address>
ssh admin@<IPv4 address>
- Turn custom config into repo of admin for convenience
mkdir repos
cp -R /etc/nixos/configuration/ repos/
cd repos/configuration/
git init
git config user.name admin
git config user.email admin@localhost
git add .
git commit -m "initial commit"
sudo rm -r /etc/nixos/configuration/
sudo ln -s /home/admin/repos/configuration/ /etc/nixos/
sudo nixos-rebuild dry-run
- Have fun and happy hacking!