Nix 101 Course / Section 2: The Nix language
Premium

2.4 Debugging Nix with trace and breakpoints

Lesson 11 of 68 · 9:23

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

About this lesson

Sooner or later a value buried in nested let blocks is not what you expect, and you need a way to look inside. This lesson covers debugging Nix expressions with builtins.trace and the built-in breakpoint debugger, the two tools you will reach for whenever a Nix expression misbehaves.

In this video

  • builtins.trace: printing values as a side effect while the program behaves as if nothing happened
  • A quiz about trace output order, and what the answer reveals about lazy evaluation
  • Why leftover trace calls annoy everyone who imports your code, and the quieter alternative
  • Setting breakpoints with builtins.break and activating them with --debugger
  • Inspecting variable scopes, stepping, continuing and reading backtraces from a REPL inside the REPL

After this lesson

When a value deep in a Nix expression looks wrong, you can print it or pause right there and poke around, in the REPL and in nix build alike.