LinuxCommandLibrary

nix-repl

Evaluate Nix expressions interactively

TLDR

Start an interactive environment for evaluating Nix expressions

$ nix repl
copy

Load all packages from a flake (e.g. nixpkgs) into scope
$ :lf [nixpkgs]
copy

Build a package from an expression
$ :b [expression]
copy

Start a shell with package from the expression available
$ :u [expression]
copy

Start a shell with dependencies of the package from the expression available
$ :s [expression]
copy

SYNOPSIS

nix-repl []

PARAMETERS


    An optional Nix expression file to load when the REPL starts. Any definitions in this file will be available within the REPL session.

DESCRIPTION

The `nix-repl` command provides an interactive environment for evaluating Nix expressions. It allows users to experiment with the Nix language, inspect values, and test configurations without having to build entire packages or systems. The REPL (Read-Eval-Print Loop) reads Nix expressions entered by the user, evaluates them, prints the resulting values, and loops back to read another expression. This is a great way to quickly prototype Nix code, debug configurations, or learn the Nix language. You can define variables, load files, and use built-in functions. The REPL also supports tab completion for identifiers and file paths, making it easier to write Nix expressions. It can be invoked with an optional file to pre-load expressions. Its primary use is for development and debugging of Nix expressions.

USAGE

Simply type `nix-repl` in your terminal to start the REPL. You can then enter Nix expressions at the prompt. For example:
nix-repl> 1 + 1
2
To load a file, use:
nix-repl somefile.nix
To quit the REPL, type :q or press Ctrl+D.

FEATURES

The `nix-repl` provides tab completion, history, and basic editing features. It supports all standard Nix language features, including functions, sets, lists, and attribute sets. You can also import external Nix files using the import function. The repl provides access to the nixpkgs collection, for example using

SEE ALSO

nix-build(1), nix-instantiate(1), nix(1)

Copied to clipboard