4.2 Remote builds and deployments with nixos-rebuild
Lesson 18 of 28 · 8:59
Video chapters
-
0:00 Flakes, non-flakes, and remote hosts
-
1:51 Remote build and deployment flow
-
4:45 How nixos-rebuild works internally
-
7:54 Substitutes, scripting, and next steps
Transcript
Flakes, non-flakes, and remote hosts
0:00 Okay, so after we demystified a bit what it actually means to run nixos-rebuild as it creates a top-level derivation and from there basically uses the switcher script. We have also seen how we can create a system from a flake and from a non-flake default.nix file or however we call it. So we can use --flake or --file to address what system we actually want to build. The next parameters which are interesting now is that we can define the build host to be another one and the target host to be another one.
0:36 Typically you would address them via SSH. So this is the host name via which this is reachable over network and this is the user name which we are logging in as and the SSH keys that you have configured for your user would be reused for that. How does this like really work? The cool thing is that with flakes we can basically say that on our laptop where we are running nixos-rebuild we can either have the repository checked out locally or we refer to it via some git repository.
1:11 So instead of writing ".my system" you could say "github: and then path to your repository" and then refer to a system from there that you don't even have checked out. So this is pretty useful. And then of course the laptop can be the system that evaluates your system and builds it and also deploys to it to itself. Or you can define the build and/or target host independently. So you can say "ok I'm running a slow laptop and it cannot build its own system" then we can add --build-host and define a bigger system that builds it for us and then deploy locally.
The full transcript comes with the lesson.
About this lesson
Your laptop does not have to build or run the system it deploys. This lesson shows how --build-host and --target-host combine into every common deployment scenario, what gets copied where during a remote deployment, and how to keep slow connections out of the way.
In this video
- Building on a big machine and deploying to a small one, or using two machines that are both not your laptop
- Deploying straight from a Git repository you haven't even checked out
- The copy steps of a remote deployment and the moment the target system actually changes
- A design decision in
nixos-rebuildthat can make transfers slow and flags for changing that - The four generic steps of any NixOS deployment, so you can script your own
After this lesson
You can deploy NixOS to remote machines with only nixos-rebuild and SSH.