mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
20866a7031
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 <shea@shealevy.com>
26 lines
517 B
Nix
26 lines
517 B
Nix
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
|