nix icon indicating copy to clipboard operation
nix copied to clipboard

catAttrs seems to remove `meta.position`

Open jonringer opened this issue 3 years ago • 6 comments

Describe the bug In nix 2.5.1, catAttrs seemed to have set the attr position to its call site:

nix-repl> perl534Packages.ModuleBuild.meta.position
"/home/jon/projects/nixpkgs/lib/attrsets.nix:369"

which refers to the zipAttrsWithNames implementation:

      value = f name (catAttrs name sets);

However, in nix 2.6+, this now seems to just remove position altogether:

# 2.6.
nix-repl> perl534Packages.ModuleBuild.meta ? "position"
false

# 2.7.0pre20220127_558c4ee
nix-repl> perl534Packages.ModuleBuild.meta ? "position"
false

Steps To Reproduce

Repeat above

Expected behavior

nix-repl> perl534Packages.ModuleBuild.meta.position
"/home/jon/project/nixpkgs/pkgs/top-level/perl-packages.nix:13938"

nix-env --version output

Issue in 2.5, 2.6, and 2.7.0pre

This seems to be impacting the repology parser. https://github.com/NixOS/nixpkgs/pull/158548

jonringer avatar Feb 09 '22 23:02 jonringer

I found a potential short term solution, and this is probably a rare scenario

https://github.com/NixOS/nixpkgs/pull/158856

jonringer avatar Feb 10 '22 01:02 jonringer

https://github.com/NixOS/nix/blob/master/src/libexpr/primops.cc#L2511 is probably the culprit here

pennae avatar Mar 09 '22 18:03 pennae

looking at other builtins: most of them do not set positions for attributes they create. this isn't currently fixable without a lot of const_casting (which might make merging a fix rather hard), but if #6218 gets merged it'll be pretty easy to fix.

pennae avatar Mar 09 '22 19:03 pennae

looking at other builtins: most of them do not set positions for attributes they create. this isn't currently fixable without a lot of const_casting (which might make merging a fix rather hard), but if #6218 gets merged it'll be pretty easy to fix.

I was able to find a workaround within nixpkgs, this is a pretty low priority now

jonringer avatar Mar 09 '22 19:03 jonringer

it would be good to have positions on attributes from builtins though, since every instance of recursiveUpdate now doesn't have positions on its attrs any more. there may be more sets affected, not just perl. :slightly_frowning_face:

pennae avatar Mar 09 '22 19:03 pennae

You would see a position error in https://repology.org/log/10896122

jonringer avatar Mar 09 '22 20:03 jonringer