Nix Repl
Interactive Nix expression evaluator. Useful for exploring nixpkgs, testing derivations, and debugging Nix values.
Launch
nix repl # bare repl
nix repl '<nixpkgs>' # load nixpkgs
nix repl /path/to/flake # load a flake
nix repl --file default.nix # load a nix fileCommon commands
| Command | Description |
|---|---|
:? | Show help |
:p <expr> | Evaluate and print expression |
<name> = <expr> | Variable assignment |
:env | Print environment |
:a <expr> | Add expression attrset to variable scope |
:l <expr> | Load and merge attribute set into scope |
:lf <path> | Load a flake into scope |
:doc <expr> | Show documentation for an attribute |
:e <expr> | Open expression in $EDITOR |
:b <drv> | Build a derivation |
:sh <expr> | Load a devshell |
:t <expr> | Show the type of an expression |
:q | Quit |
<Tab> | Autocomplete |
Typical session
nix-repl> :l <nixpkgs>
Added 20000 variables.
nix-repl> pkgs.hello
«derivation /nix/store/...-hello-2.12.1.drv»
nix-repl> pkgs.hello.meta.description
"A program that produces a familiar, friendly greeting"
nix-repl> :b pkgs.hello
nix-repl> lib.strings.toUpper "hello"
"HELLO"
nix-repl> builtins.attrNames pkgs.python3.pkgs | lib.take 5
[ "Babel" "Flask" "Jinja2" "Markdown" "Pillow" ]Loading a flake
nix-repl> :l .# # load current flake outputs
nix-repl> packages.x86_64-linux.default
«derivation ...»
nix-repl> nixosConfigurations.myhost.config.networking.hostName
"myhost"Tips
- Use
<Tab>heavily — attribute set completion is very helpful :bbuilds to/tmp/nix-repl-*and symlinks result- Multi-line: wrap in
( ... )or uselet ... in - Access
builtinsdirectly:builtins.nixVersion,builtins.currentSystem