aboutsummaryrefslogtreecommitdiff
path: root/src/libcmd/repl-overlays.nix
diff options
context:
space:
mode:
authorRebecca Turner <rbt@sent.as>2024-04-04 16:26:25 -0700
committerRebecca Turner <rbt@sent.as>2024-04-08 17:11:47 -0700
commit727b43478cce8ebbd0f58530878d3af80a3ba233 (patch)
tree07950876b289786c388c28119d55cc9839c27b73 /src/libcmd/repl-overlays.nix
parente55fc5af715020d79ec91c856447303737bf3015 (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/libcmd/repl-overlays.nix')
-rw-r--r--src/libcmd/repl-overlays.nix8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libcmd/repl-overlays.nix b/src/libcmd/repl-overlays.nix
new file mode 100644
index 000000000..33ce49482
--- /dev/null
+++ b/src/libcmd/repl-overlays.nix
@@ -0,0 +1,8 @@
+info:
+initial:
+functions:
+let final = builtins.foldl'
+ (prev: function: prev // (function info final prev))
+ initial
+ functions;
+in final