lib: make extender available on self-references#210976
Conversation
|
Well, this one certainly seems like the most minimal / cleanest of the three PRs to me (but of course I'm biased because I wrote it 😄). My goal here was less ambitious than @ncfavier's: I seek only to make the I am not trying to replace the Perhaps this PR might be less contentious than the others due to the fact that is pretty much a pure bugfix? |
|
Yes, this change should go through regardless. There were discussions about the change in my PR: #157056 (comment) #157056 (comment) |
|
The evaluator report is a bit worrying though. +6.20% in cpu time? Let's double check EDIT: that's better. |
roberth
left a comment
There was a problem hiding this comment.
This is useful beyond lib.extend and fits the pattern of mkDerivation
mkDerivation (self: { passthru.xyz = self.overrideAttrs foo; })
This happens every now and then. 40%? No problem. Those are quite interesting actually. ~50 invocations of extend Coincidence? Yes, but also no. Anyway, the numbers are in the ballpark. |
|
Am I crazy for thinking thart +6.20% is actually quite huge for a change almost no one will benefit from? |
|
Yeah, @ncfavier was expressing concern about this change if it really increases evaluation time by that much. However, he re-ran the evaluator and it came back with +0.15% CPU time. I'm guessing that these timings are somewhat noisy because we are running in a very cloudy environment. |
Description of changes
Existing Behavior
At present, recursive self-references to extensible sets do not themselves have a reference to the extender function:
Note: What you should be noticing is that
r1andr2contain a function,extend, but none of the captured self-references have access to it.Behavior With Change
With this change, the extender function becomes available:
It behaves just as you would expect it would; Any extension made on the parent set shows up in captured child extensions:
Why?
This obviously makes the self-references "higher-fidelity" in the sense that they more closely match the final composed set. However, one might ask "Why do you actually need this?", given that the examples given so far seem somewhat abstract and arcane. The answer is: (NixOS, etc.) module composition!
The
libarg passed to modules happens to be an extensible set self-reference. Here's a manual traceback of code showing how that happens:nixpkgs/lib/modules.nix
Line 261 in a21493d
nixpkgs/lib/modules.nix
Line 1 in a21493d
nixpkgs/lib/default.nix
Line 33 in a21493d
nixpkgs/lib/default.nix
Lines 10 to 11 in a21493d
The effect of this is that the
libreceived by modules is not a full-featured nixpkgslib. The impact of this is that you can't do the thing I'm trying to do: compose an extended nixpkgslibin a module.Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)nixos/doc/manual/md-to-db.shto update generated release notes