diff options
author | Rebecca Turner <rbt@sent.as> | 2024-04-04 16:26:25 -0700 |
---|---|---|
committer | Rebecca Turner <rbt@sent.as> | 2024-04-08 17:11:47 -0700 |
commit | 727b43478cce8ebbd0f58530878d3af80a3ba233 (patch) | |
tree | 07950876b289786c388c28119d55cc9839c27b73 /src/libexpr/eval-settings.hh | |
parent | e55fc5af715020d79ec91c856447303737bf3015 (diff) |
Add `repl-overlays`
Adds a `repl-overlays` option, which specifies files that can overlay
and modify the top-level bindings in `nix repl`. For example, with the
following contents in `~/.config/nix/repl.nix`:
info: final: prev: let
optionalAttrs = predicate: attrs:
if predicate
then attrs
else {};
in
optionalAttrs (prev ? legacyPackages && prev.legacyPackages ? ${info.currentSystem})
{
pkgs = prev.legacyPackages.${info.currentSystem};
}
We can run `nix repl` and use `pkgs` to refer to `legacyPackages.${currentSystem}`:
$ nix repl --repl-overlays ~/.config/nix/repl.nix nixpkgs
Lix 2.90.0
Type :? for help.
Loading installable 'flake:nixpkgs#'...
Added 5 variables.
Loading 'repl-overlays'...
Added 6 variables.
nix-repl> pkgs.bash
«derivation /nix/store/g08b5vkwwh0j8ic9rkmd8mpj878rk62z-bash-5.2p26.drv»
Change-Id: Ic12e0f2f210b2f46e920c33088dfe1083f42391a
Diffstat (limited to 'src/libexpr/eval-settings.hh')
-rw-r--r-- | src/libexpr/eval-settings.hh | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/libexpr/eval-settings.hh b/src/libexpr/eval-settings.hh index c78213255..e8bfe81a4 100644 --- a/src/libexpr/eval-settings.hh +++ b/src/libexpr/eval-settings.hh @@ -124,6 +124,42 @@ struct EvalSettings : Config This is useful for debugging warnings in third-party Nix code. )"}; + + PathsSetting replOverlays{this, Paths(), "repl-overlays", + R"( + A list of files containing Nix expressions that can be used to add + default bindings to [`nix + repl`](@docroot@/command-ref/new-cli/nix3-repl.md) sessions. + + Each file is called with three arguments: + 1. An [attribute set](@docroot@/language/values.html#attribute-set) + containing at least a + [`currentSystem`](@docroot@/language/builtin-constants.md#builtins-currentSystem) + attribute (this is identical to + [`builtins.currentSystem`](@docroot@/language/builtin-constants.md#builtins-currentSystem), + except that it's available in + [`pure-eval`](@docroot@/command-ref/conf-file.html#conf-pure-eval) + mode). + 2. The top-level bindings produced by the previous `repl-overlays` + value (or the default top-level bindings). + 3. The final top-level bindings produced by calling all + `repl-overlays`. + + For example, the following file would alias `pkgs` to + `legacyPackages.${info.currentSystem}` (if that attribute is defined): + + ```nix + info: final: prev: + if prev ? legacyPackages + && prev.legacyPackages ? ${info.currentSystem} + then + { + pkgs = prev.legacyPackages.${info.currentSystem}; + } + else + { } + ``` + )"}; }; extern EvalSettings evalSettings; |