the docs say that the arguments for an overlay is info/prev/final, but it's actually info/final/prev. this fixes the docs both in the nix.conf manual as well as in the `nix repl` help text Change-Id: I3de5c122e7e77cc3f4e4550e3741d6a6e906ea20
3.9 KiB
R""(
Note: this command's interface is based heavily around installables, which you may want to read about first (nix --help).
Examples
-
Display all special commands within the REPL:
# nix repl nix-repl> :? -
Evaluate some simple Nix expressions:
# 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:
# 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> 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!
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.
Adding default variables in REPL sessions
It is possible to automatically load variables from a list of files
into each new REPL session using the
repl-overlays
configuration option.
Each file should contain a Nix function taking three taking and returning an attribute set. These three arguments are:
- An attribute set
containing at least a
currentSystemattribute (this is identical tobuiltins.currentSystem, except that it's available inpure-evalmode). - The final top-level bindings produced by calling all
repl-overlays. - The top-level bindings produced by the previous
repl-overlaysvalue (or the default top-level bindings).
Examples
-
Aliasing
legacyPackages.${currentSystem}topkgsA file named
/home/alice/my-overlays.nixcontaining the following code would, iflegacyPackagesexists, add a variable namedpkgsinto the global REPL scope, which returns the value oflegacyPackages.${currentSystem}.info: final: prev: if prev ? legacyPackages && prev.legacyPackages ? ${info.currentSystem} then { pkgs = prev.legacyPackages.${info.currentSystem}; } else { }This file can be loaded automatically for every REPL session by adding it to the value of
repl-overlaysinsidenix.conf. For a single session, it is possible to add it using--option repl-overlays /home/alice/my-overlay.nix:# nix repl --option repl-overlays /home/alice/my-overlay.nix nixpkgs nix-repl> pkgs == legacyPackages.${builtins.currentSystem} true nix-repl> pkgs.hello «derivation /nix/store/qdzln99hynf92vrz8sz91hlf1dmb1vdy-hello-2.12.2.drv»
See the nix.conf
repl-overlays
documentation for more information.
)""