1.6 Upgrading NixOS and pinning your system with a flake
Lesson 6 of 28 · 10:33
Video chapters
-
0:00 How NixOS Updates Work
-
1:14 Inspecting nix-channel and nixpkgs Source
-
2:50 Upgrading with nix-channel and nixos-rebuild
-
4:46 Why nixos-rebuild switch Matters
-
6:12 Problems with Unpinned nixpkgs
-
7:34 Enabling Flakes on NixOS
-
8:40 Creating a Flake-Based System Config
-
10:03 Updating and Pinning with Flakes
Transcript
How NixOS Updates Work
0:00 Okay, so in the last videos we installed the NixOS system and then we changed it, installed a nice desktop manager and now we're happy with it and in this video we're going to talk about how do we even upgrade NixOS because there's multiple ways to do that and in the next video we'll kind of discuss how we can get rid of old system versions. So how do we update a NixOS system? What's interesting is that when we go to /etc/nixos where our config resides and we open the configuration we can see that there's kind of we just expect there's a nixpkgs attribute set but where does it come from?
0:42 We don't define any version here and it magically comes from somewhere so where is that somewhere? For that we need to run the nix-channel application as root and here we can see that we have a NixOS unstable channel pinned. So nix-channel is a tool that can manipulate what is behind NixOS. So we can basically say we run the nix repl and then we have the path NixOS which basically
Inspecting nix-channel and nixpkgs Source
1:19 points to a NixOS checkout from nixpkgs and that is what we're using there. So let's exit the REPL again and we can generally say nix-channel --upgrade, of course it's update and now it downloads the latest and greatest nixpkgs from unstable which takes a second and there we are.
The full transcript comes with the lesson.
About this lesson
Where does the pkgs in your configuration.nix actually come from, and how do you update it? This lesson upgrades a NixOS system the classic way with channels, then turns the configuration into a flake, so the exact nixpkgs version lives in a lock file. Two machines built from the same repository then get exactly the same system.
In this video
- The hidden channel behind
/etc/nixosand how to update it - What
nixos-rebuild switchrestarts on a live system and when you still want a reboot - Enabling flakes from within the NixOS configuration itself
- Turning
configuration.nixinto a flake withnixosConfigurations, and the naming detail that saves you typing - Updating with
nix flake update, and keeping the configuration in a Git repository instead of/etc/nixos
After this lesson
Your system is pinned and reproducible: you can rebuild it next week or on a colleague's machine and get the same result.