7. Exploring nixpkgs with the REPL

Turn nixpkgs from an opaque monolith into something you can poke at, one expression at a time

By now you can read a NixOS configuration and you have a flake that builds a real system. But there's a nagging gap between reading Nix and knowing Nix. You write pkgs.python3.pkgs.requests into a config, run a rebuild that takes ninety seconds, and only then find out you got the attribute path wrong. You copy a lib.mkForce from a gist without ever having seen what it returns. Nixpkgs is a hundred-thousand-package attribute set and, most of the time, you're navigating it blind.

nix repl closes that gap. It's an interactive prompt where you type a Nix expression and see what it evaluates to — no rebuild, no file to save, no guessing. Instead of committing a change and waiting to find out whether it was right, you ask nixpkgs directly: what is pkgs.hello? what version? what does it depend on? does this host's config actually have SSH enabled? This article is a tour of the REPL as an exploration tool — the single fastest way to learn what's actually inside nixpkgs and inside your own configuration.

Why the REPL is worth learning well

Nix's evaluation is pure and lazy: an expression always evaluates to the same value, and nothing is computed until you ask for it. That combination is exactly what makes a REPL so powerful here. You can load the entire universe of nixpkgs in a fraction of a second (laziness), and every expression you type is reproducible and side-effect-free (purity) — so poking around can't break anything. The REPL is a read-only microscope over a giant, otherwise-invisible tree.

Starting a session

There are a few ways in, and the right one depends on what you want to look at.

The barest form gives you a prompt with only the builtins namespace and nothing else in scope — useful for language experiments, but not for exploring packages:

Just the language

$ nix repl
Welcome to Nix 2.24. Type :? for help.
nix-repl> 1 + 1
2
nix-repl> builtins.attrNames { z = 1; a = 2; }
[ "a" "z" ]

To explore packages, you need pkgs in scope. The classic, pre-flake way is to hand the REPL the <nixpkgs> from your search path. This special form imports nixpkgs and dumps its top-level attributes straight into scope, so hello, lib, stdenv, and every package name are available as bare identifiers:

The classic channel-based entry

$ nix repl '<nixpkgs>'
Added 21734 variables.
nix-repl> hello.version
"2.12.1"
nix-repl> lib.version
"24.11.20241130"

This relies on <nixpkgs> resolving through NIX_PATH — the same mutable, global search path a flakes-first setup is trying to get away from. It still works, and it's a quick way to grab a scratch pkgs, but it's not the version your flake is pinned to.

The flakes-native way is to start a plain nix repl and then load a flake with :lf (load-flake). Pointing it at nixpkgs gives you a pkgs that matches a specific revision rather than whatever your channel happens to be:

Loading nixpkgs as a flake

$ nix repl
nix-repl> :lf nixpkgs
Added 5 variables.
nix-repl> legacyPackages.x86_64-linux.hello.version
"2.12.1"

:lf adds the flake's outputs to scope — for nixpkgs that's legacyPackages, lib, and a few others. Packages live under legacyPackages.<system> because a flake has to be explicit about which platform it's building for; there's no ambient "current system." That path is verbose, so we'll fix it with :a in a moment.

The most useful entry of all, though, is loading your own flake to inspect the exact system it builds. Run nix repl from your configuration's directory and :lf .:

Loading your own configuration

$ cd /etc/nixos
$ nix repl
nix-repl> :lf .
Added 14 variables.
nix-repl> builtins.attrNames nixosConfigurations
[ "bluewhale" "seahorse" ]

Now the flake's outputs — nixosConfigurations, packages, devShells, inputs, and so on — are all in scope, and you can drill into the fully-evaluated config of any host. We'll come back to this; it's where the REPL earns its keep as a debugging tool.

The command cheat sheet

Anything starting with a colon is a REPL command, not Nix. Type :? to see the full list; these are the ones you'll actually reach for:

The commands worth memorizing

:l <path>    load a Nix file, adding its attributes to scope
:lf <ref>    load a flake, adding its outputs to scope
:a <expr>    add the attributes of a set to scope (so you can drop a prefix)
:p <expr>    print a value RECURSIVELY, forcing every lazy sub-value
:t <expr>    describe the type of a value ("a string", "a set", "a lambda")
:e <expr>    open the file that DEFINES a package/function in $EDITOR
:b <drv>     actually build a derivation and print its output path
:r           reload every file you've loaded (pick up edits)
:q           quit
:?           list all commands

Two of these change how you move around, and they're the ones beginners miss. :a (add) takes a set and lifts its attributes into the top-level scope so you can stop typing a prefix. After :lf nixpkgs, the prefix legacyPackages.x86_64-linux. gets old fast — so lift it once:

:a flattens a prefix into scope

nix-repl> :a legacyPackages.x86_64-linux
Added 21734 variables.
nix-repl> hello.version
"2.12.1"
nix-repl> :a lib
Added 641 variables.
nix-repl> version
"24.11.20241130"

Now hello, ripgrep, and every lib helper are bare names. This is exactly what nix repl '<nixpkgs>' does for you automatically — it's just :a under the hood.

The other essential is tab completion on attribute paths. Type pkgs.pyth and hit Tab and the REPL completes it against the live attribute set — this alone turns "guess the attribute name and wait for a rebuild to find out" into "press Tab." It works at every level: pkgs.python3.pkgs.req<Tab> will complete to requests. When you're not sure what lives under a node, completion is faster than any search of the manual.

Eager questions, lazy answers

Here's the one behavior that surprises everyone. Ask the REPL for a package and you don't get a tidy printout — you get a placeholder:

A bare evaluation stops at the surface

nix-repl> pkgs.hello
«derivation /nix/store/…-hello-2.12.1.drv»
nix-repl> pkgs.hello.meta
{ available = «thunk»; broken = «thunk»; description = «thunk»; … }

Those «thunk» markers are laziness made visible. When you type an expression, Nix evaluates it just far enough to show you the shape — the top-level attribute names — and leaves every value as an unforced thunk. It has no reason to compute description until something demands it, so it doesn't. This is the same laziness that lets you load all of nixpkgs instantly: the REPL only ever computes the sliver you actually reach for.

To see through the thunks, use :p (print), which forces the value recursively:

:p forces the whole value

nix-repl> :p pkgs.hello.meta.description
"A program that produces a familiar, friendly greeting"
nix-repl> :p pkgs.hello.meta
{ available = true; broken = false; description = "A program that produces…"; homepage = "https://www.gnu.org/software/hello/"; license = { … }; … }

Reaching a single leaf like .meta.description forces just that leaf, so plain evaluation is enough. Ask for a whole set and you need :p to drill all the way to the bottom instead of stopping at a wall of thunks.

That two-step rhythm — evaluate to see the shape, then :p to force the details — is the core loop of exploring in the REPL:

The explore loop: shape first, then forcepkgs.hello.metayou type an expression{ description =«thunk»; … }lazy shape, values unforced"A program thatproduces…"forced, concrete valueeval:pread the answer, refine the path, ask again — no rebuild in the loopLaziness means "eval" is cheap even against all of nixpkgs; :p pays only for what you force.

Drilling into nixpkgs

With pkgs and lib in scope, the whole collection is browsable. Start with the metadata that's most useful when picking or pinning a package:

What is this package, exactly?

nix-repl> pkgs.ripgrep.version
"14.1.0"
nix-repl> pkgs.ripgrep.pname
"ripgrep"
nix-repl> :p pkgs.ripgrep.meta.description
"A utility that combines the usability of The Silver Searcher with the raw speed of grep"
nix-repl> :p pkgs.ripgrep.meta.license.spdxId
"MIT"

Want to know where a package name comes from, or what the top level even contains? builtins.attrNames pkgs returns every attribute name — but be warned, it's a list of tens of thousands of entries, so you rarely want to print it raw. It's far more useful piped through lib helpers, which we'll get to. A more targeted question is drilling into a package's own sub-namespaces. Python's per-interpreter package set lives under pkgs.python3.pkgs:

Language package sets nest under the interpreter

nix-repl> pkgs.python3.version
"3.12.7"
nix-repl> pkgs.python3.pkgs.requests.version
"2.32.3"
nix-repl> pkgs.python3.pkgs.requests.pname
"requests"

This is the attribute path you'd put in a config, verified before you write it. Tab completion after pkgs.python3.pkgs. lists every Python library nixpkgs packages for that interpreter.

Because a package is a derivation, you can also inspect the two store paths that matter most. drvPath is the path of the build recipe (the .drv); outPath is where the built result will land once realized. Both are computed by pure evaluation — no build required:

A derivation's two addresses

nix-repl> pkgs.hello.drvPath
"/nix/store/xg5y3q…-hello-2.12.1.drv"
nix-repl> pkgs.hello.outPath
"/nix/store/0d71yg…-hello-2.12.1"
nix-repl> "${pkgs.hello}/bin/hello"
"/nix/store/0d71yg…-hello-2.12.1/bin/hello"

That last line is the trick configs use constantly: interpolating a package into a string splices in its outPath, which is how you build an absolute path to a binary inside a store directory without ever hardcoding a hash.

Detective work

Exploration becomes debugging the moment you have a concrete question. Here are the recurring ones.

What does this package actually depend on? Every derivation exposes its inputs. buildInputs are runtime/link dependencies; nativeBuildInputs are build-time tools. They come back as a list of derivations, so :p and map turn them into readable names:

Reading a dependency list

nix-repl> map (d: d.pname or d.name) pkgs.ripgrep.buildInputs
[ "pcre2" ]
nix-repl> map (d: d.pname or d.name) pkgs.hello.nativeBuildInputs
[ ]

The .pname or .name guards against inputs that don't set a pname — the safe-access idiom from the language article, earning its keep.

Where is this defined? :e opens the source of a package or function in your $EDITOR, jumping straight to the line via the value's meta.position. This is the fastest way to answer "how is this actually implemented?" or "what arguments does this override take?" without hunting through the nixpkgs tree by hand:

Jump to the source

nix-repl> :e pkgs.hello
# opens pkgs/by-name/he/hello/package.nix in $EDITOR
nix-repl> :e lib.mkForce
# opens the lib file where mkForce is defined

Will this expression even work? This is the REPL's highest-value use: testing a snippet before it goes into a config and costs you a rebuild. Suppose you're about to write a list comprehension over some hosts, or a lib.mkIf guard. Try it in isolation first:

Rehearse before you commit

nix-repl> lib.range 1 5
[ 1 2 3 4 5 ]
nix-repl> map (n: "node-${toString n}") (lib.range 1 3)
[ "node-1" "node-2" "node-3" ]
nix-repl> map (p: p.pname) (lib.optionals true [ pkgs.git pkgs.htop ])
[ "git" "htop" ]

If it evaluates cleanly here, it'll evaluate cleanly in your config — and you found out in a second instead of after a ninety-second rebuild that ends in a stack trace.

Actually build it. When you do want the artifact, :b realizes a derivation right from the prompt and prints the output path — handy for checking that a package you've tweaked still builds, or grabbing a binary to test:

:b builds on the spot

nix-repl> :b pkgs.hello
This derivation produced the following outputs:
  out -> /nix/store/0d71yg…-hello-2.12.1

Interrogating your own system

The single best reason to reach for the REPL: it can evaluate the fully-merged configuration of a host, exactly as nixos-rebuild sees it. No more wondering whether an option ended up true after all your modules, imports, and defaults have been combined — ask the config tree directly. Load your flake and walk into config:

Ground truth for "is this actually set?"

nix-repl> :lf .
nix-repl> nixosConfigurations.bluewhale.config.services.openssh.enable
true
nix-repl> nixosConfigurations.bluewhale.config.networking.hostName
"bluewhale"
nix-repl> nixosConfigurations.bluewhale.config.services.openssh.settings.PasswordAuthentication
false

This is the resolved value after module merging — the real answer, not what any single file says. If a setting isn't what you expected, this tells you the truth in one line instead of a rebuild-and-inspect cycle.

That path is long, so :a pays off again. Lift the config once and explore freely:

Lift the host's config into scope

nix-repl> :a nixosConfigurations.bluewhale
Added 7 variables.
nix-repl> config.system.stateVersion
"24.11"
nix-repl> :p (map (p: p.pname or p.name) config.environment.systemPackages)
[ "git" "htop" "ripgrep" "nix" … ]
nix-repl> config.services.nginx.enable
false

Now config, options, pkgs, and lib are all bare names scoped to this exact host. You can enumerate installed packages, check a service, or read any option's final value — the whole system laid open as a plain attribute set.

You can go one level up, too. options holds the option definitions themselves — their types, defaults, and even the description text — which is a way to answer "what does this option mean and what's its default?" without leaving the prompt:

Options carry their own documentation

nix-repl> :p options.services.openssh.enable.description
"Whether to enable the OpenSSH secure shell daemon…"
nix-repl> options.services.openssh.ports.default
[ 22 ]

Tips that pay for themselves

Tame huge attribute sets with lib. builtins.attrNames pkgs is unreadable, but filtered it's a search engine. lib.filterAttrs keeps only the entries matching a predicate; wrap the result in :p to force it:

Search nixpkgs from the prompt

nix-repl> :p builtins.filter (n: lib.hasPrefix "python3" n) (builtins.attrNames pkgs)
[ "python3" "python3Full" "python3Minimal" "python3Packages" … ]
nix-repl> :p lib.filterAttrs (n: v: lib.hasPrefix "ripgrep" n) pkgs
{ ripgrep = «derivation…»; ripgrep-all = «derivation…»; }

Trace values mid-evaluation with builtins.trace. When an expression is more tangled than a single line, builtins.trace msg value prints msg to stderr and returns value untouched — a printf you can splice into the middle of a computation to see what's flowing through it:

trace is Nix's printf

nix-repl> let x = 21; in builtins.trace "x is ${toString x}" (x * 2)
trace: x is 21
42

The trace: line goes to stderr as a side channel; the expression still evaluates to 42. Because it returns its second argument unchanged, you can drop it into an existing expression without altering the result.

Reload after editing. If you loaded a file with :l and then edit it in another window, :r re-reads everything you've loaded so the REPL sees your changes — no need to restart and re-navigate.

Keep the session running. The REPL holds all your added scope and history, so the natural workflow is one long-lived nix repl beside your editor: change a file, :r, re-check the value, repeat. That tight loop — no save-and-rebuild round trip — is genuinely the fastest feedback in the entire Nix toolchain, and it's why experienced Nix users keep a REPL open the way others keep a shell.

Try it: explore a miniature nixpkgs

The prompt below is a stand-in for nix repl with a small, hand-built pkgs and lib already in scope. Drill into a package's version and meta, list attribute names, force a lazy value with the ideas from this article, and try a lib helper — the same moves you just read, without leaving the page. One simplification to note: this simulator forces values one level deep when it prints, so a bare pkgs.hello.meta shows its fields already evaluated rather than as «thunk» — use :p to expand nested sets fully.

Key Takeaways

  • The REPL is the fastest feedback loop in Nix: type an expression, see its value — no file to save, no rebuild, and because evaluation is pure and lazy, poking around is free and can't break anything.
  • Get into scope the right way: nix repl '<nixpkgs>' for a quick channel-based pkgs, or nix repl + :lf . to load your own flake and inspect the exact system it builds. Use :a to flatten a long prefix (like a host's config) into bare names.
  • Shape first, then force: a bare evaluation shows top-level names with «thunk» placeholders; :p forces a value recursively so you see all the way down. Tab completion drills attribute paths without guessing.
  • Answer real questions: a package's version/meta, its buildInputs, its drvPath/outPath, where it's :e-defined, and whether it :b-builds — plus rehearsing any expression before it touches your config.
  • Interrogate your own system: nixosConfigurations.HOST.config.… gives the fully-merged value of any option after all modules are combined — ground truth, in one line, instead of a rebuild-and-check cycle.
  • Sharpen it with lib and trace: lib.filterAttrs/hasPrefix turn the giant attribute set into a searchable index, and builtins.trace is a printf you can splice into any expression.

You now have a microscope for nixpkgs and for your own configuration — a way to ask precise questions and get instant, reproducible answers. That skill is about to become essential, because the next step is changing what nixpkgs gives you. In Overlays & Overrides we'll pin a package to a different version, patch one that's broken, and layer our own changes onto the whole collection — and the REPL is exactly how you'll check that each override did what you meant.