From 20866a7031ca823055a221653b77986faa167329 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 15 Jul 2013 15:53:14 -0400 Subject: Delay evaulation of `with` attrs until a variable lookup needs them Evaluation of attribute sets is strict in the attribute names, which means immediate evaluation of `with` attribute sets rules out some potentially interesting use cases (e.g. where the attribute names of one set depend in some way on another but we want to bring those names into scope for some values in the second set). The major example of this is overridable self-referential package sets (e.g. all-packages.nix). With immediate `with` evaluation, the only options for such sets are to either make them non-recursive and explicitly use the name of the overridden set in non-overridden one every time you want to reference another package, or make the set recursive and use the `__overrides` hack. As shown in the test case that comes with this commit, though, delayed `with` evaluation allows a nicer third alternative. Signed-off-by: Shea Levy --- tests/lang/eval-okay-delayed-with.exp | 1 + tests/lang/eval-okay-delayed-with.nix | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/lang/eval-okay-delayed-with.exp create mode 100644 tests/lang/eval-okay-delayed-with.nix (limited to 'tests') diff --git a/tests/lang/eval-okay-delayed-with.exp b/tests/lang/eval-okay-delayed-with.exp new file mode 100644 index 000000000000..eaacb55c1aff --- /dev/null +++ b/tests/lang/eval-okay-delayed-with.exp @@ -0,0 +1 @@ +"b-overridden" diff --git a/tests/lang/eval-okay-delayed-with.nix b/tests/lang/eval-okay-delayed-with.nix new file mode 100644 index 000000000000..82934d6a9d5e --- /dev/null +++ b/tests/lang/eval-okay-delayed-with.nix @@ -0,0 +1,26 @@ +let + pkgs_ = with pkgs; { + a = derivation { + name = "a"; + system = builtins.currentSystem; + builder = "/bin/sh"; + args = [ "-c" "touch $out" ]; + inherit b; + }; + + b = derivation { + name = "b"; + system = builtins.currentSystem; + builder = "/bin/sh"; + args = [ "-c" "touch $out" ]; + }; + + c = b; + }; + + packageOverrides = p: { + b = derivation (p.b.drvAttrs // { name = "b-overridden"; }); + }; + + pkgs = pkgs_ // (packageOverrides pkgs_); +in pkgs.a.b.name -- cgit 1.4.1