Demos / Section 1: Live demos
Free

1.3 Deploy NixOS to any cloud server with nixos-anywhere

Lesson 3 of 3 · 14:06

placeholder thumbnail

Create a free account to watch this lesson

Free account · no credit card needed

Video chapters

  1. 0:00 Introduction to NixOS Anywhere
  2. 1:17 Creating the Hetzner VM
  3. 2:40 Flake and Disko Configuration
  4. 5:49 Deploying NixOS with nixos-anywhere
  5. 8:55 Booting into the New NixOS System
  6. 10:43 Rebuilding and Enabling Apache
  7. 12:24 Removing SSH and Final Thoughts
Transcript

Introduction to NixOS Anywhere

0:00 Hey, in this video, I'm going to show you how to use NixOS anywhere to deploy NixOS systems on any kind of cloud VM or cloud bare metal system or real hardware or whatever. In this example, we're going to use Hetzner, of course, it would just work on OVH, on Netcup, on whatever other hoster you can kind of imagine. The important thing is that we can basically say, okay, let's create a new resource and that might be a virtual machine, a bare metal server or whatever, where we say, okay, in this case, we'll just select whatever the cheapest Intel VM possible.

0:38 And then we see here already, it doesn't give us NixOS, right? So does that mean we can't easily deploy NixOS there? No, it doesn't. What I'm going to show you is that Hetzner is one of the perfect examples for that, despite them not supporting NixOS, at least not like how you would expect. It doesn't mean that we cannot deploy NixOS there. So let's just select Ubuntu here, networking, standard stuff, add my SSH key, blah, blah, blah, stay on the default settings and just create this VM.

1:15 And then, yeah, kind of random things pop up.

Sign in for the full transcript.

About this lesson

Your hoster does not offer a NixOS image. Almost none of them do. That turns out not to matter: this demo rents the cheapest virtual machine at Hetzner, boots the Ubuntu image it insists on, and a few minutes later the machine is running a NixOS configuration from a flake, partitioned and formatted exactly as declared. Then it gets a web server, without anybody logging in to install one.

In this video

  • Renting a plain cloud VM with no NixOS option, and the small detour around a boot restriction that stock images like to have
  • Declaring disks with disko: partitions, filesystems and mount points as configuration, instead of a checklist you follow once and forget
  • The single nix run command that takes over a running foreign system and leaves NixOS in its place
  • What scrolls over the console during the takeover, and why no NixOS installer image is ever involved
  • Life after the first deployment: adding a web service with nixos-rebuild switch --target-host, and then taking SSH off the server on purpose

After this lesson

You can put NixOS on anything that boots Linux and answers SSH, cloud VM or bare metal in an office. You also know why a declarative deployment lets you ship a server that nobody, including you, can log into.

Links: