2020-12-09 12:07:01 +00:00
|
|
|
|
R""(
|
|
|
|
|
|
|
|
|
|
# Examples
|
|
|
|
|
|
|
|
|
|
* Display all special commands within the REPL:
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
# nix repl
|
|
|
|
|
nix-repl> :?
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* Evaluate some simple Nix expressions:
|
|
|
|
|
|
|
|
|
|
```console
|
|
|
|
|
# nix repl
|
|
|
|
|
|
|
|
|
|
nix-repl> 1 + 2
|
|
|
|
|
3
|
|
|
|
|
|
|
|
|
|
nix-repl> map (x: x * 2) [1 2 3]
|
|
|
|
|
[ 2 4 6 ]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* Interact with Nixpkgs in the REPL:
|
|
|
|
|
|
|
|
|
|
```console
|
2022-03-11 18:26:08 +00:00
|
|
|
|
# nix repl --file example.nix
|
|
|
|
|
Loading Installable ''...
|
|
|
|
|
Added 3 variables.
|
2020-12-09 12:07:01 +00:00
|
|
|
|
|
2022-03-11 18:26:08 +00:00
|
|
|
|
# nix repl --expr '{a={b=3;c=4;};}'
|
|
|
|
|
Loading Installable ''...
|
|
|
|
|
Added 1 variables.
|
|
|
|
|
|
|
|
|
|
# nix repl --expr '{a={b=3;c=4;};}' a
|
|
|
|
|
Loading Installable ''...
|
|
|
|
|
Added 1 variables.
|
|
|
|
|
|
2022-06-15 13:02:36 +00:00
|
|
|
|
# nix repl --extra_experimental_features 'flakes repl-flake' nixpkgs
|
2022-03-11 18:26:08 +00:00
|
|
|
|
Loading Installable 'flake:nixpkgs#'...
|
|
|
|
|
Added 5 variables.
|
|
|
|
|
|
|
|
|
|
nix-repl> legacyPackages.x86_64-linux.emacs.name
|
|
|
|
|
"emacs-27.1"
|
|
|
|
|
|
|
|
|
|
nix-repl> legacyPackages.x86_64-linux.emacs.name
|
|
|
|
|
"emacs-27.1"
|
|
|
|
|
|
|
|
|
|
nix-repl> :q
|
|
|
|
|
|
2022-03-11 18:52:08 +00:00
|
|
|
|
# nix repl --expr 'import <nixpkgs>{}'
|
2022-03-11 18:26:08 +00:00
|
|
|
|
|
|
|
|
|
Loading Installable ''...
|
|
|
|
|
Added 12439 variables.
|
2020-12-09 12:07:01 +00:00
|
|
|
|
|
|
|
|
|
nix-repl> emacs.name
|
|
|
|
|
"emacs-27.1"
|
|
|
|
|
|
|
|
|
|
nix-repl> emacs.drvPath
|
|
|
|
|
"/nix/store/lp0sjrhgg03y2n0l10n70rg0k7hhyz0l-emacs-27.1.drv"
|
|
|
|
|
|
2021-11-26 15:03:07 +00:00
|
|
|
|
nix-repl> drv = runCommand "hello" { buildInputs = [ hello ]; } "hello; hello > $out"
|
2020-12-09 12:07:01 +00:00
|
|
|
|
|
2021-11-26 15:03:07 +00:00
|
|
|
|
nix-repl> :b drv
|
2020-12-09 12:07:01 +00:00
|
|
|
|
this derivation produced the following outputs:
|
|
|
|
|
out -> /nix/store/0njwbgwmkwls0w5dv9mpc1pq5fj39q0l-hello
|
|
|
|
|
|
|
|
|
|
nix-repl> builtins.readFile drv
|
|
|
|
|
"Hello, world!\n"
|
2021-11-26 15:03:07 +00:00
|
|
|
|
|
|
|
|
|
nix-repl> :log drv
|
|
|
|
|
Hello, world!
|
2020-12-09 12:07:01 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# Description
|
|
|
|
|
|
|
|
|
|
This command provides an interactive environment for evaluating Nix
|
|
|
|
|
expressions. (REPL stands for 'read–eval–print loop'.)
|
|
|
|
|
|
|
|
|
|
On startup, it loads the Nix expressions named *files* and adds them
|
|
|
|
|
into the lexical scope. You can load addition files using the `:l
|
|
|
|
|
<filename>` command, or reload all files using `:r`.
|
|
|
|
|
|
|
|
|
|
)""
|