nix3-repl(1)

✨ nix repl β€” the nix3-repl(1) page, bestie edition ✨

General Commands Manual who? She's serving "interactive Nix evaluation" and honestly she ate πŸ’…

Warning β€” this program is experimental and its interface is subject to change. Not me being dramatic, that's literally what it says. Things may move around. Prepare your heart 🫠

🌸 NAME 🌸

nix repl β€” start an interactive environment for evaluating Nix expressions

Bestie. You type Nix in, Nix talks back. It's giving conversation. It's giving relationship πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

nix repl [option…] installables…

πŸ¦‹ EXAMPLES πŸ¦‹

Okay so first up, if you wanna see every special command the REPL has hiding in it:

# nix repl
nix-repl> :?

(Yes :? is the cheat code. Iconic.)

Next, some simple Nix math so you can see the vibe:

# nix repl

nix-repl> 1 + 2
3

nix-repl> map (x: x * 2) [1 2 3]
[ 2 4 6 ]

map (x: x * 2) [1 2 3] returning [ 2 4 6 ]?? She's so real for that 🧚

And now, the main event β€” hanging out with Nixpkgs in the REPL:

# nix repl --file example.nix
Loading Installable ''...
Added 3 variables.

# 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.

# nix repl --extra-experimental-features 'flakes' nixpkgs
Loading Installable 'flake:nixpkgs#'...
Added 5 variables.

nix-repl> legacyPackages.x86_64-linux.emacs.name
"emacs-27.1"

nix-repl> :q

# nix repl --expr 'import <nixpkgs>{}'

Loading Installable ''...
Added 12439 variables.

nix-repl> emacs.name
"emacs-27.1"

nix-repl> emacs.drvPath
"/nix/store/lp0sjrhgg03y2n0l10n70rg0k7hhyz0l-emacs-27.1.drv"

nix-repl> drv = runCommand "hello" { buildInputs = [ hello ]; } "hello; hello > $out"

nix-repl> :b drv
this derivation produced the following outputs:
out -> /nix/store/0njwbgwmkwls0w5dv9mpc1pq5fj39q0l-hello

nix-repl> builtins.readFile drv
"Hello, world!\n"

nix-repl> :log drv
Hello, world!

12439 variables?? She said "I contain multitudes" and meant it πŸ˜­πŸ‘‘


πŸ’œ DESCRIPTION πŸ’œ

This command gives you an interactive environment for evaluating Nix expressions. And yes, REPL stands for "read–eval–print loop" β€” read it, evaluate it, print it, loop it, repeat forever, that's the whole personality πŸ”

On startup, it loads the Nix expressions named files and adds them into the lexical scope. You can load more files using the :l <filename> command, or reload all files using :r. Very much giving "come back here I'm not done with you" energy 🫢


πŸ‘‘ OPTIONS πŸ‘‘

  • --stdin β€” read installables from the standard input. No default installable applied. (Piping things in like a little gift 🎁)

πŸ”₯ Common evaluation options πŸ”₯

  • --arg name expr β€” pass the value expr as the argument name to Nix functions.
  • --arg-from-file name path β€” pass the contents of file path as the argument name to Nix functions.
  • --arg-from-stdin name β€” pass the contents of stdin as the argument name to Nix functions.
  • --argstr name string β€” pass the string string as the argument name to Nix functions.
  • --debugger β€” start an interactive environment if evaluation fails. So when it goes wrong you get to poke at it instead of just screaming πŸ’€
  • --eval-store store-url β€” the URL of the Nix store to use for evaluation, i.e. to store derivations (.drv files) and inputs referenced by them.
  • --impure β€” allow access to mutable paths and repositories. (Living dangerously, I respect it πŸ™ˆ)
  • --include / -I path β€” add path to search path entries used to resolve lookup paths.

This option may be given multiple times.

Paths added through -I take precedence over the nix-path configuration setting and the NIX_PATH environment variable. She doesn't queue, she goes first πŸ’…

  • --override-flake original-ref resolved-ref β€” override the flake registries, redirecting original-ref to resolved-ref.
  • --commit-lock-file β€” commit changes to the flake's lock file.
  • --inputs-from flake-url β€” use the inputs of the specified flake as registry entries.
  • --no-registries β€” don't allow lookups in the flake registries.
DEPRECATED β€” use --no-use-registries instead.
  • --no-update-lock-file β€” do not allow any updates to the flake's lock file.
  • --no-write-lock-file β€” do not write the flake's newly generated lock file.
  • --output-lock-file flake-lock-path β€” write the given lock file instead of flake.lock within the top-level flake.
  • --override-input input-path flake-url β€” override a specific flake input (e.g. dwarffs/nixpkgs). The input path must not be empty. This implies --no-write-lock-file.
  • --recreate-lock-file β€” recreate the flake's lock file from scratch.
DEPRECATED β€” use nix flake update instead.
  • --reference-lock-file flake-lock-path β€” read the given lock file instead of flake.lock within the top-level flake.
  • --update-input input-path β€” update a specific flake input (ignoring its previous entry in the lock file).
DEPRECATED β€” use nix flake update instead.
  • --debug β€” set the logging verbosity level to 'debug'.
  • --log-format format β€” set the format of log output; one of raw, internal-json, bar or bar-with-logs.
  • --print-build-logs / -L β€” print full build logs on standard error.
  • --quiet β€” decrease the logging verbosity level. Shhh 🀫
  • --verbose / -v β€” increase the logging verbosity level. Tell me EVERYTHING πŸ—£οΈ

⭐ Miscellaneous global options ⭐

  • --help β€” show usage information.
  • --offline β€” disable substituters and consider all previously downloaded files up-to-date.
  • --option name value β€” set the Nix configuration setting name to value (overriding nix.conf).
  • --refresh β€” consider all previously downloaded files out-of-date.
  • --repair β€” during evaluation, rewrite missing or corrupted files in the Nix store. During building, rebuild missing or corrupted store paths. Fixer-upper energy πŸ”§βœ¨
  • --version β€” show version information.

🧚 Options that change the interpretation of installables 🧚

  • --expr expr β€” interpret installables as attribute paths relative to the Nix expression expr.
  • --file / -f file β€” interpret installables as attribute paths relative to the Nix expression stored in file. If file is the character -, then a Nix expression is read from standard input. Implies --impure.
Note β€” see man nix.conf for overriding configuration settings with command line flags. Go read her too, she's part of the lore πŸ“–

And that's the whole page, bestie β€” nix3-repl(1) from the General Commands Manual, signed, sealed, delivered. No cap, go open that REPL and evaluate something. :q when you're done. 🫢✨

πŸ“¦ where this page comes from