{"slug": "nixos-on-hetzner-cloud", "title": "NixOS on Hetzner Cloud", "summary": "This article provides a step-by-step guide for setting up a NixOS server on a Hetzner Cloud instance, including partitioning the disk, installing NixOS, and configuring an admin user with SSH access. It also explains how to manage the system configuration via a Git repository by creating a symbolic link from `/etc/nixos/` to a user-controlled repo. The process concludes with instructions for rebuilding the system and verifying the setup.", "body_md": "This is the gist of how to setup a [NixOS](https://nixos.org/) server on a [Hetzner Cloud](https://www.hetzner.com/cloud) instance with an `admin` user, ssh access and configuration management via git.\n\n1. Create a Hetzner Cloud instance and click to enter it.\n2. Stop the instance (top right corner icon).\n3. Go to *ISO Images*.\n4. Search for \"nixos\" and click *mount*.\n![ISO Images tab of a Hetzner Cloud instance with the NixOS image already mounted](https://user-images.githubusercontent.com/30078229/152664634-d580278d-5dd2-468f-b113-f2581d69a5b1.png)\n5. Start the instance again (top right corner icon).\n6. Open the console (top right corner icon).\n7. Get the IP address by executing `ip --brief --color address`. The address can also be optained from the Hetzner Cloud web interface.\n```\nlo               UNKNOWN        127.0.0.1/8 ::1/128\nenp61s0          UP             <IPv4 address>/24 <IPv6 address>/64\n```\n8. Download your public ssh key to the machine. If you have a GitHub account you can download it from there.\n```bash\nmkdir ~/.ssh\ncurl -L https://github.com/<username>.keys | tee -a .ssh/authorized_keys\n```\n9. Log on from your computer on via ssh.\n```bash\nssh nixos@<IPv4 address>\n```\n10. Partition, format and mountthe disk.\n```bash\nsudo -i\n# Create a GPT partition table.\nparted /dev/sda -- mklabel msdos\n# Add the root partition.\nparted /dev/sda -- mkpart primary 1MiB 100%\npartprobe\n# Format the partition.\nmkfs.ext4 -L nixos /dev/sda1\n# Mount root.\nmount /dev/disk/by-label/nixos /mnt\n```\n11. Generate the initial configuration and install.\n```bash\nnixos-generate-config --root /mnt\n# Set boot device.\nsed -e 's/^.*boot\\.loader\\.grub\\.device.*$/  boot.loader.grub.device = \"\\/dev\\/sda\";/g' -i /mnt/etc/nixos/configuration.nix\n# Create a directory to manage configurations and import it in the generated config.\nmkdir /mnt/etc/nixos/configuration/\nsed -e 's/\\.\\/hardware-configuration\\.nix/.\\/hardware-configuration.nix\\n      .\\/configuration/g' -i /mnt/etc/nixos/configuration.nix\n```\n12. Open `/mnt/etc/nixos/configuration/default.nix` with an editor like `vim` or `nano` and paste the following.\n```nix\n{ config, pkgs, ... }:\n\n{\n  imports =\n    [\n      ./user.nix\n    ];\n  environment.systemPackages = with pkgs; [\n    vim\n    wget\n    git\n    htop bottom\n  ];\n  services.openssh.enable = true;\n}\n```\n13. Open `/mnt/etc/nixos/configuration/user.nix` with an editor and paste the following to create an account with the name *admin*. **Replace the public ssh key with yours**.\n```nix\n{ config, pkgs, ... }:\n\n{\n  imports = [\n  ];\n  users = {\n    users = {\n      admin = {\n        isNormalUser = true;\n        extraGroups = [ \"wheel\" ];\n        initialHashedPassword = \"\";\n        openssh.authorizedKeys.keys = [ \"ssh-ed25519 AAAA....\" ];\n      };\n    };\n  };\n}\n```\n15. Perform installation.\n```bash\nnixos-install --no-root-passwd\n```\n16. Enter the mounted installation and set a password for the admin account.\n```bash\nnixos-enter --root /mnt\npasswd admin\nexit\n```\n17. Shut down the machine.\n```bash\npoweroff\n```\n18. Unmount the ISO in the Hetzner Cloud interface and start the machine again.\n19. Log on via SSH.\n```bash\n# Remove old host key from install system.\nssh-keygen -R <IPv4 address>\n# Log in as admin\nssh admin@<IPv4 address>\n```\n20. Turn custom config into repo of admin for convenience\n```bash\nmkdir repos\ncp -R /etc/nixos/configuration/ repos/\ncd repos/configuration/\n# Initialize repository with placeholder configuration.\ngit init\ngit config user.name admin\ngit config user.email admin@localhost\ngit add .\ngit commit -m \"initial commit\"\n# Remove replace old files with symbolic link.\nsudo rm -r /etc/nixos/configuration/\nsudo ln -s /home/admin/repos/configuration/ /etc/nixos/\n# Test by rebuilding system\nsudo nixos-rebuild dry-run\n```\n21. Have fun and happy hacking!", "url": "https://wpnews.pro/news/nixos-on-hetzner-cloud", "canonical_source": "https://gist.github.com/cyber-murmel/8b726b45047907a842a9dc9db2618b0a", "published_at": "2022-02-06 01:30:58+00:00", "updated_at": "2026-05-22 22:36:28.563831+00:00", "lang": "en", "topics": ["cloud-computing", "open-source", "developer-tools"], "entities": ["NixOS", "Hetzner Cloud", "GitHub"], "alternates": {"html": "https://wpnews.pro/news/nixos-on-hetzner-cloud", "markdown": "https://wpnews.pro/news/nixos-on-hetzner-cloud.md", "text": "https://wpnews.pro/news/nixos-on-hetzner-cloud.txt", "jsonld": "https://wpnews.pro/news/nixos-on-hetzner-cloud.jsonld"}}