Nix command/repl

From NixOS Wiki
Jump to: navigation, search

This article is about the nix repl subcommand.


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


$ nix repl FLAGS... FILES...


  • --arg NAME EXPR argument to be passed to Nix functions
  • --argstr NAME STRING string-valued argument to be passed to Nix functions
  • --impure allow access to mutable paths and repositories
  • -I, --include PATH add a path to the list of locations used to look up <...> file names
  • --override-flake ORIGINAL-REF RESOLVED-REF override a flake registry value


If you run :? inside a repl instance, it will print out the available commands. A list is given below (as of version 2.5.1)

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
  :e <expr>     Open package or function in $EDITOR
  :i <expr>     Build derivation, then install result into current profile
  :l <path>     Load Nix expression and add it to scope
  :lf <ref>     Load Nix flake 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
  :doc <expr>   Show documentation of a builtin function
  :log <expr>   Show logs for a derivation
$ 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>
# download/build package and open in a nix-shell
nix-repl> :u sl
[nix-shell:~]$ sl # choo choo...

See also