aboutsummaryrefslogtreecommitdiff
path: root/tests/functional
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 /tests/functional
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 'tests/functional')
-rw-r--r--tests/functional/repl_characterization/data/extra_data/repl-overlay-fail.nix1
-rw-r--r--tests/functional/repl_characterization/data/extra_data/repl-overlay-no-dotdotdot.nix6
-rw-r--r--tests/functional/repl_characterization/data/extra_data/repl-overlay-no-formals.nix1
-rw-r--r--tests/functional/repl_characterization/data/extra_data/repl-overlay-packages-is-pkgs.nix4
-rw-r--r--tests/functional/repl_characterization/data/extra_data/repl-overlays-compose-1.nix7
-rw-r--r--tests/functional/repl_characterization/data/extra_data/repl-overlays-compose-2.nix6
-rw-r--r--tests/functional/repl_characterization/data/repl_overlays.nix3
-rw-r--r--tests/functional/repl_characterization/data/repl_overlays.test5
-rw-r--r--tests/functional/repl_characterization/data/repl_overlays_compose.nix3
-rw-r--r--tests/functional/repl_characterization/data/repl_overlays_compose.test7
-rw-r--r--tests/functional/repl_characterization/data/repl_overlays_destructure_without_dotdotdot_errors.test10
-rw-r--r--tests/functional/repl_characterization/data/repl_overlays_destructure_without_formals_ok.test5
-rw-r--r--tests/functional/repl_characterization/data/repl_overlays_error.test22
-rw-r--r--tests/functional/repl_characterization/extra_data/repl-overlay-fail.nix1
-rw-r--r--tests/functional/repl_characterization/extra_data/repl-overlay-no-dotdotdot.nix1
-rw-r--r--tests/functional/repl_characterization/extra_data/repl-overlay-packages-is-pkgs.nix4
-rw-r--r--tests/functional/repl_characterization/extra_data/repl-overlays-compose-1.nix7
-rw-r--r--tests/functional/repl_characterization/extra_data/repl-overlays-compose-2.nix6
-rw-r--r--tests/functional/repl_characterization/repl_characterization.cc7
19 files changed, 105 insertions, 1 deletions
diff --git a/tests/functional/repl_characterization/data/extra_data/repl-overlay-fail.nix b/tests/functional/repl_characterization/data/extra_data/repl-overlay-fail.nix
new file mode 100644
index 000000000..426127916
--- /dev/null
+++ b/tests/functional/repl_characterization/data/extra_data/repl-overlay-fail.nix
@@ -0,0 +1 @@
+info: final: prev: builtins.abort "uh oh!"
diff --git a/tests/functional/repl_characterization/data/extra_data/repl-overlay-no-dotdotdot.nix b/tests/functional/repl_characterization/data/extra_data/repl-overlay-no-dotdotdot.nix
new file mode 100644
index 000000000..e242d644d
--- /dev/null
+++ b/tests/functional/repl_characterization/data/extra_data/repl-overlay-no-dotdotdot.nix
@@ -0,0 +1,6 @@
+let
+ puppy = "doggy";
+in
+ {currentSystem}: final: prev: {
+ inherit puppy;
+ }
diff --git a/tests/functional/repl_characterization/data/extra_data/repl-overlay-no-formals.nix b/tests/functional/repl_characterization/data/extra_data/repl-overlay-no-formals.nix
new file mode 100644
index 000000000..cf31550c0
--- /dev/null
+++ b/tests/functional/repl_characterization/data/extra_data/repl-overlay-no-formals.nix
@@ -0,0 +1 @@
+info: final: prev: {}
diff --git a/tests/functional/repl_characterization/data/extra_data/repl-overlay-packages-is-pkgs.nix b/tests/functional/repl_characterization/data/extra_data/repl-overlay-packages-is-pkgs.nix
new file mode 100644
index 000000000..57895a97f
--- /dev/null
+++ b/tests/functional/repl_characterization/data/extra_data/repl-overlay-packages-is-pkgs.nix
@@ -0,0 +1,4 @@
+info: final: prev:
+{
+ pkgs = final.packages.x86_64-linux;
+}
diff --git a/tests/functional/repl_characterization/data/extra_data/repl-overlays-compose-1.nix b/tests/functional/repl_characterization/data/extra_data/repl-overlays-compose-1.nix
new file mode 100644
index 000000000..055e9ea0f
--- /dev/null
+++ b/tests/functional/repl_characterization/data/extra_data/repl-overlays-compose-1.nix
@@ -0,0 +1,7 @@
+info: final: prev:
+{
+ var = prev.var + "b";
+
+ # We can access the final value of `var` here even though it isn't defined yet:
+ varUsingFinal = "final value is: " + final.newVar;
+}
diff --git a/tests/functional/repl_characterization/data/extra_data/repl-overlays-compose-2.nix b/tests/functional/repl_characterization/data/extra_data/repl-overlays-compose-2.nix
new file mode 100644
index 000000000..e88407311
--- /dev/null
+++ b/tests/functional/repl_characterization/data/extra_data/repl-overlays-compose-2.nix
@@ -0,0 +1,6 @@
+info: final: prev:
+{
+ var = prev.var + "c";
+
+ newVar = "puppy";
+}
diff --git a/tests/functional/repl_characterization/data/repl_overlays.nix b/tests/functional/repl_characterization/data/repl_overlays.nix
new file mode 100644
index 000000000..09f115f03
--- /dev/null
+++ b/tests/functional/repl_characterization/data/repl_overlays.nix
@@ -0,0 +1,3 @@
+{
+ packages.x86_64-linux.default = "my package";
+}
diff --git a/tests/functional/repl_characterization/data/repl_overlays.test b/tests/functional/repl_characterization/data/repl_overlays.test
new file mode 100644
index 000000000..56f1392e1
--- /dev/null
+++ b/tests/functional/repl_characterization/data/repl_overlays.test
@@ -0,0 +1,5 @@
+Check basic `repl-overlays` functionality.
+@args --repl-overlays
+@args ${PWD}/extra_data/repl-overlay-packages-is-pkgs.nix
+ nix-repl> pkgs
+ { default = "my package"; }
diff --git a/tests/functional/repl_characterization/data/repl_overlays_compose.nix b/tests/functional/repl_characterization/data/repl_overlays_compose.nix
new file mode 100644
index 000000000..aa6596dc7
--- /dev/null
+++ b/tests/functional/repl_characterization/data/repl_overlays_compose.nix
@@ -0,0 +1,3 @@
+{
+ var = "a";
+}
diff --git a/tests/functional/repl_characterization/data/repl_overlays_compose.test b/tests/functional/repl_characterization/data/repl_overlays_compose.test
new file mode 100644
index 000000000..b674a55be
--- /dev/null
+++ b/tests/functional/repl_characterization/data/repl_overlays_compose.test
@@ -0,0 +1,7 @@
+Check that multiple `repl-overlays` can compose together
+@args --repl-overlays
+@args "${PWD}/extra_data/repl-overlays-compose-1.nix ${PWD}/extra_data/repl-overlays-compose-2.nix"
+ nix-repl> var
+ "abc"
+ nix-repl> varUsingFinal
+ "final value is: puppy"
diff --git a/tests/functional/repl_characterization/data/repl_overlays_destructure_without_dotdotdot_errors.test b/tests/functional/repl_characterization/data/repl_overlays_destructure_without_dotdotdot_errors.test
new file mode 100644
index 000000000..daf1f27bd
--- /dev/null
+++ b/tests/functional/repl_characterization/data/repl_overlays_destructure_without_dotdotdot_errors.test
@@ -0,0 +1,10 @@
+`repl-overlays` that try to parse out the `info` argument without a `...` error.
+@args --repl-overlays
+@args ${PWD}/extra_data/repl-overlay-no-dotdotdot.nix
+@should-start false
+ error: Expected first argument of repl-overlays to have ... to allow future versions of Lix to add additional attributes to the argument
+ at $TEST_DATA/extra_data/repl-overlay-no-dotdotdot.nix:4:3:
+ 3| in
+ 4| {currentSystem}: final: prev: {
+ | ^
+ 5| inherit puppy;\n
diff --git a/tests/functional/repl_characterization/data/repl_overlays_destructure_without_formals_ok.test b/tests/functional/repl_characterization/data/repl_overlays_destructure_without_formals_ok.test
new file mode 100644
index 000000000..3aa89e434
--- /dev/null
+++ b/tests/functional/repl_characterization/data/repl_overlays_destructure_without_formals_ok.test
@@ -0,0 +1,5 @@
+`repl-overlays` that don't destructure the `info` argument are OK.
+@args --repl-overlays
+@args ${PWD}/extra_data/repl-overlay-no-formals.nix
+ nix-repl> 1
+ 1
diff --git a/tests/functional/repl_characterization/data/repl_overlays_error.test b/tests/functional/repl_characterization/data/repl_overlays_error.test
new file mode 100644
index 000000000..2d8702df1
--- /dev/null
+++ b/tests/functional/repl_characterization/data/repl_overlays_error.test
@@ -0,0 +1,22 @@
+`repl-overlays` that fail to evaluate should error.
+@args --repl-overlays
+@args ${PWD}/extra_data/repl-overlay-fail.nix
+@should-start false
+ error:
+ … while calling the 'foldl'' builtin
+ at «string»:5:13:
+ 4| functions:
+ 5| let final = builtins.foldl'
+ | ^
+ 6| (prev: function: prev // (function info final prev))
+
+ … in the right operand of the update (//) operator
+ at «string»:6:37:
+ 5| let final = builtins.foldl'
+ 6| (prev: function: prev // (function info final prev))
+ | ^
+ 7| initial
+
+ (stack trace truncated; use '--show-trace' to show the full trace)
+
+ error: evaluation aborted with the following error message: 'uh oh!'
diff --git a/tests/functional/repl_characterization/extra_data/repl-overlay-fail.nix b/tests/functional/repl_characterization/extra_data/repl-overlay-fail.nix
new file mode 100644
index 000000000..426127916
--- /dev/null
+++ b/tests/functional/repl_characterization/extra_data/repl-overlay-fail.nix
@@ -0,0 +1 @@
+info: final: prev: builtins.abort "uh oh!"
diff --git a/tests/functional/repl_characterization/extra_data/repl-overlay-no-dotdotdot.nix b/tests/functional/repl_characterization/extra_data/repl-overlay-no-dotdotdot.nix
new file mode 100644
index 000000000..1cced3324
--- /dev/null
+++ b/tests/functional/repl_characterization/extra_data/repl-overlay-no-dotdotdot.nix
@@ -0,0 +1 @@
+{currentSystem}: final: prev: {}
diff --git a/tests/functional/repl_characterization/extra_data/repl-overlay-packages-is-pkgs.nix b/tests/functional/repl_characterization/extra_data/repl-overlay-packages-is-pkgs.nix
new file mode 100644
index 000000000..57895a97f
--- /dev/null
+++ b/tests/functional/repl_characterization/extra_data/repl-overlay-packages-is-pkgs.nix
@@ -0,0 +1,4 @@
+info: final: prev:
+{
+ pkgs = final.packages.x86_64-linux;
+}
diff --git a/tests/functional/repl_characterization/extra_data/repl-overlays-compose-1.nix b/tests/functional/repl_characterization/extra_data/repl-overlays-compose-1.nix
new file mode 100644
index 000000000..055e9ea0f
--- /dev/null
+++ b/tests/functional/repl_characterization/extra_data/repl-overlays-compose-1.nix
@@ -0,0 +1,7 @@
+info: final: prev:
+{
+ var = prev.var + "b";
+
+ # We can access the final value of `var` here even though it isn't defined yet:
+ varUsingFinal = "final value is: " + final.newVar;
+}
diff --git a/tests/functional/repl_characterization/extra_data/repl-overlays-compose-2.nix b/tests/functional/repl_characterization/extra_data/repl-overlays-compose-2.nix
new file mode 100644
index 000000000..e88407311
--- /dev/null
+++ b/tests/functional/repl_characterization/extra_data/repl-overlays-compose-2.nix
@@ -0,0 +1,6 @@
+info: final: prev:
+{
+ var = prev.var + "c";
+
+ newVar = "puppy";
+}
diff --git a/tests/functional/repl_characterization/repl_characterization.cc b/tests/functional/repl_characterization/repl_characterization.cc
index ae4d4030f..f3c6065aa 100644
--- a/tests/functional/repl_characterization/repl_characterization.cc
+++ b/tests/functional/repl_characterization/repl_characterization.cc
@@ -184,7 +184,12 @@ REPL_TEST(no_nested_debuggers);
REPL_TEST(regression_9917);
REPL_TEST(regression_9918);
REPL_TEST(regression_l145);
-REPL_TEST(stack_vars);
+REPL_TEST(repl_overlays);
+REPL_TEST(repl_overlays_compose);
+REPL_TEST(repl_overlays_destructure_without_dotdotdot_errors);
+REPL_TEST(repl_overlays_destructure_without_formals_ok);
+REPL_TEST(repl_overlays_error);
REPL_TEST(repl_printing);
+REPL_TEST(stack_vars);
}; // namespace nix