3.2 Your first dev shell with nix-shell
Lesson 19 of 68 · 6:43
Video chapters
-
0:00 Setting Up a Nix Shell for TMUX
-
1:28 Creating shell.nix with Required Build Tools
-
3:14 Running the Project Inside Nix Shell
-
5:01 Swapping Packages and Nesting Shells
Transcript
Setting Up a Nix Shell for TMUX
0:00 Okay, so let's forget what we did with Docker and system-wide stuff and so on. Let's have a look at TMUX, how we build it with Nix and a proper Nix shell. So of course, when we just open the project, where we have a look at the project tree, I have no make installed, no GCC and so on. So you see that the system is pretty fresh and we would want to keep it like that. And of course, we can run Nix shell -p and then pile up like GCC, Automake, Autoconf, and so on.
0:35 Let's not do that because we will have to remember the whole line and then tell our colleagues, hey, you just enter these 30 kilometers of command line and then you will also be able to develop in this project. Let's drop that. We have also seen in earlier videos how to use Nix shell with or without the dash here in between the with Flakes or without Flakes variant. However, in this project, when we say, okay, we'll be developing this for the next month, let's have a proper setup here. We can create a new file that would be called shell.nix and here we can say let packages equals import nixpkgs.
1:19 In proper production setups, you wouldn't want to use this and instead have a pinned packages location that you commit with your code because then your colleagues will all
Sign in for the full transcript.
About this lesson
One file with a handful of lines, and your project carries its complete toolchain with it. No Docker image, no system-wide installs, no setup chapter in the README. We build a real dev shell for a real C project (tmux) on a machine that has no compiler installed at all.
In this video
- Your first
shell.nix, and why it beats the endlessnix-shell -pcommand your colleagues would have to memorize - Swapping a single tool and rebuilding: Nix downloads one package where Docker would rebuild a whole layer stack
- Nesting shells: pull in an extra tool for a minute, exit, and it's gone. Try that with containers.
- The workflow that makes "clone, nix-shell, build" the entire onboarding for every new team member
Free user context
If you have only seen the free videos from this course so far, let's add some context from the other videos:
- The project that we have checked out here is the popular tmux tool, a shell multiplexer. We create a developer shell for it.
- This example does not use flakes, as we learn about those later in section 9.
- Flakes are just a different framing around the
pkgs.mkShellcall which stays the same. 😊
After this lesson
You can give any project a reproducible development environment that your whole team gets by running one command.