2.2 The Nix REPL as a power tool
Lesson 9 of 68 · 9:55
Video chapters
-
0:00 Why Use the Nix REPL
-
1:14 Exploring Nix Expressions and Builtins
-
3:00 Inspecting Packages and Documentation
-
5:00 Building and Entering Packages from the REPL
-
7:00 Overriding Hello and Using the REPL Daily
Transcript
Why Use the Nix REPL
0:00 Okay, so before we learn the mechanics of the Nix language and the syntax and what not, we'll be very often in a situation of not knowing if a certain Nix expression even makes sense. And then imagine you have a thousand lines Nix expression and you want to test if a part of it would even work. How to do that? So, I want to show you the Nix REPL. In general, a REPL is a read, eval and print tool.
0:30 Python has the same thing. So, for example, I can show that for you with Python. So when we just launch Python 3 without any parameters, we get in a Python shell. And then we can say one plus one like this, or we could say S is a set. And then we can say S update A and B printed. And you can play around with this to see if your expressions even make sense or if we get errors or what not.
1:06 For example, one divided by zero would be a division by zero error. And you can try out these things. How is this exception called? What not? And then with that knowledge, go back into the editor and write code that actually works.
Sign in for the full transcript.
About this lesson
The Nix REPL is the fastest way to test a Nix expression before it ends up buried in a thousand line file. This Nix REPL tutorial shows how to evaluate code interactively, read documentation without opening a browser, and inspect, build and even patch packages from nixpkgs, all from one prompt.
In this video
- Starting
nix repl, evaluating expressions, and reading built-in docs with:docand tab completion - Loading all of nixpkgs with
nix repl --fileand using tab completion as a quick package search - Inspecting package metadata: description, home page, license, and what the
...in the output hints at - Building a package with
:band dropping into its shell with:u, straight from the REPL - A live demo: patching GNU hello so it prints a different greeting, without editing a single file
After this lesson
You keep a REPL open next to your editor and test every idea there first, which saves you from writing Nix code that never had a chance to work.