Conversation
This is useful for a potential pure-Nix implementation of NixOS#3904.
|
I would rather we had |
I don't think pure eval mode disallows any of the unsafe builtins. Do we need to restrict this to lambdas? We should have position information for most Nix expressions. |
|
I believe that the reason it's called unsafe is because it basically guarantees that your function is impure as it then starts depending on the exact source making the derivation. Perhaps it should be named differently, but then it's inconsistent. I want this functionality for debugging mostly, anyway, and I can see it being potentially useful outside of the REPL in tracing or other places. I do not believe it is a risk for restricted evaluation mode because you'd have to first evaluate the file that's not in the Nix store before you get any information on it. As for restricting it to lambdas, that's a fantastic question I do not know the answer to and I was mostly staring at lambdas too hard to notice. |
|
@matthewbauer I looked into it. If we just have the value, it is not possible to get the position of things other than lambdas. See It might be possible to take advantage of lazy evaluation in some way to achieve this, since perhaps we might have the appropriate context still existing prior to the forceValue call, but I don't know enough about Nix internals to implement this idea. I have also made it so If there isn't any other proposed use of |
This is useful for a potential pure-Nix implementation of #3904 as
unsafeGetAttrPosdoes not appear to be usable for finding lambdas that are defined by import, for example.One thing I noticed while implementing this is that the way that Nix exposes Pos for things in the REPL as a set is surprising:
in that it doesn't report whether the
fileattribute is actually a file or arbitrary Nix source. It is unclear whether it's possible to rely on there being a leading space to determine whether a givenfileis actually Nix code.