9.7 Exercise: flakify a real project
Lesson 65 of 68 · 20:07
Video chapters
-
0:00 Introducing Flakes and the Existing Nix Setup
-
2:00 Porting release.nix Logic into flake.nix
-
5:15 Conditional Package Exposure by Platform
-
9:00 Adding the Default Dev Shell
-
12:15 Using the Alternative Flake Template
-
15:30 Reconciling Flake Locks with nixtamal
Transcript
Introducing Flakes and the Existing Nix Setup
0:00 Okay, let's practice a bit with Flakes. We have already worked with this repository, right? And there we used the release.nix file. So how does the project look like with the Flake? In general, we're gonna use all the information that is in the release.nix file and just port it to a flake.nix file. That project has been used, if you don't remember, in the overlay section. So if you want to understand the release.nix file or the overlay or something like that, please go back to that section and have a look at it.
0:38 We handled that in depth and now this is about transforming the same thing into Flakes. What's interesting is that in Git repositories, which this one is, Flake commands can't see files if they are not have been added with Git add before, right? So please note that whenever you see like, hey, so why doesn't it pick up my file? Why doesn't claim it's not there? Maybe it needs to go into your Git index first. Okay, so let's play. Let's just start from fresh as if we have never touched this repository.
1:19 And what do we have? Of course, we still have this overlay file, which actually describes the packages abcd and myapp up there and the release.nix file and the shell.nix file. And the default.nix file. So what's interesting is when we look at a default.nix file and shell.nix file, they practically just divert to those specific attributes from there, which we will not need in a Flake file.
The full transcript comes with the lesson.
About this lesson
Now it is your turn. You get a project you already know from the overlays section, complete with release.nix, shell.nix and an overlay file, and the task is to flakify it: same packages, same dev shell, now served through a flake.nix. This is where the template knowledge from the previous lessons turns into a skill you can use on your own repositories.
In this video
- Reusing the existing overlay instead of copying package definitions into the flake
- A gotcha that hits almost everyone in git repositories: the flake insists your new file does not exist
- Filtering outputs per platform, because a cross-compiled ARM package makes no sense on an ARM host
- Both flake templates applied to the same project, so you can compare them on real code
- Two lock files in one repository, and a way to end up with a single source of truth for pinning
After this lesson
You have converted a non-flake project to flakes yourself, without duplicating a single package definition, and you know how to keep flake and non-flake workflows living side by side.
Builds on: Exercise: overlay across the dep tree (8.7)
Links:
- Exercise repository: https://github.com/nixcademy/multi-project-repo
- Solution branch: https://github.com/nixcademy/multi-project-repo/tree/solution-flake