Nix-repl

From NixOS Wiki
Jump to: navigation, search

nix repl is an interactive shell to explore the Nix language as well as configurations,options and packages in Nixpkgs. It supports tab-completion.

Feature Overview

$ nix repl '<nixpkgs>'
Added 8013 variables.
nix-repl> pkgs.<tab><tab>
Display all 8013 possibilities? (y or n)
# load your systems nixos configuration
nix-repl> :l <nixpkgs/nixos>
Added 5 variables.
nix-repl> config.<tab><tab>
...
nix-repl> config.services.nginx.enable
false
# download/build package and open in a nix-shell
nix-repl> :u sl
[nix-shell:~]$ sl # choo choo...

Commands available inside nix repl

If you run :? inside a repl instance, it will print out the available commands. A list is given below (from September 2019)

nix-repl> :?
The following commands are available:

  <expr>        Evaluate and print expression
  <x> = <expr>  Bind expression to variable
  :a <expr>     Add attributes from resulting set to scope
  :b <expr>     Build derivation
  :i <expr>     Build derivation, then install result into current profile
  :l <path>     Load Nix expression and add it to scope
  :p <expr>     Evaluate and print expression recursively
  :q            Exit nix-repl
  :r            Reload all files
  :s <expr>     Build dependencies of derivation, then start nix-shell
  :t <expr>     Describe result of evaluation
  :u <expr>     Build derivation, then start nix-shell