NixOS 101 Course / Section 4: Building and deploying NixOS systems
Premium

4.3 Install NixOS on a cloud server with nixos-anywhere and disko

Lesson 19 of 28 · 10:44

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

Video chapters

  1. 0:00 Bootstrapping a New Remote NixOS System
  2. 1:58 Defining the Disk Layout and NixOS Configuration
  3. 4:17 Installing NixOS with nixos-anywhere
  4. 6:30 Rebuilding the New System with nixos-rebuild
  5. 9:11 Opening the Firewall and Wrapping Up
Transcript

Bootstrapping a New Remote NixOS System

0:00 So now after we learned how nixos-rebuild basically works and works for remote deployments, let's create a new remote deployment where we have the NixOS configuration in one repository and then we get it into a system that was not running NixOS before and then play around with that configuration. So in this example here I created a little Hetzner machine. We can basically have a look at how it looks like when it's booted. So that's the remote display. Of course, we can also SSH into it.

0:38 And what we see is that this is basically a rescue system. An important detail here is that when I created that new VM, it costs, I don't know, 15 euros per month. And you can select the Linux distribution from there and I selected Ubuntu. The thing is that Ubuntu has this security feature enabled that the kexec system call is disabled there. So for that reason, I launched a rescue system and from there we can do whatever we like.

1:09 So most importantly, we can see on this system here it has a disk called /dev/sda and it has three partitions and we will wipe them all away. So let's get out again and the configuration that we're going to flash like over this would be this one here. So you don't need to copy or write everything from the screen here. You can also go to github.com/nixcademy/nixos-anywhere-example.

The full transcript comes with the lesson.

About this lesson

Your cloud provider offers Ubuntu, but no NixOS. In this lesson we take over a fresh Hetzner VM with nixos-anywhere, declare its disk layout with disko, and then keep developing the server with plain nixos-rebuild --target-host.

In this video

  • Why we boot the rescue system instead of Ubuntu and the kexec system call that makes the takeover possible
  • A disk layout as configuration: partitions, file systems, and mount points with disko
  • One command from a foreign Linux to an installed NixOS, without any installer image
  • Adding a web server and opening the firewall
  • A server without any password, reachable only with your SSH key

After this lesson

You can put NixOS on any machine that runs Linux and accepts SSH, and maintain it from a Git repository afterwards.

Builds on: Installing NixOS by hand: partition, format, mount, install (1.4)

Links: