nix-community / nix-index

Quickly locate nix packages with specific files [maintainers=@bennofs @figsoda @raitobezarius]

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`--top-level` ignores symlinks

ncfavier opened this issue · comments

The go package in nixpkgs looks like this:

lrwxrwxrwx     1 root root     12 Jan  1  1970 bin -> share/go/bin
dr-xr-xr-x     3 root root   4.0K Jan  1  1970 share

When searching for /bin/go, the only returned entry for go.out is

go.out   15,679,861 x /nix/store/3wpbn0nv1yhb47njlb3z3vicj20cp2mj-go-1.20.2/share/go/bin/go

Thus adding --top-level does not return go.out.

I think the expected behaviour would be for nix-index to index all paths, even with possible duplicates. In this case, both /bin/go and /share/go/bin/go should be returned.

I am not sure if the metadata that nix-index processes includes the destination of the symlink. But if that's the case I agree that we should try to resolve symlinks by default (maybe with an option to disable this behaviour)

It is. If we resolve symlinks then a question arises: should a path be marked s when its last component is a symlink, or when any component is?

Just to add another example, this also hurts node packages, where $out/bin points to lib/node_modules/.bin/:

$ which pnpm
/nix/store/jxyv7qildiy960h194h4ca3wharbbpks-pnpm-8.15.3/bin/pnpm
$ ls -al /nix/store/jxyv7qildiy960h194h4ca3wharbbpks-pnpm-8.15.3/bin
lrwxrwxrwx 1 root root 21 janv.  1  1970 /nix/store/jxyv7qildiy960h194h4ca3wharbbpks-pnpm-8.15.3/bin -> lib/node_modules/.bin
$ nix-locate bin/pnpm
nodePackages.pnpm.out                               637 x /nix/store/jxyv7qildiy960h194h4ca3wharbbpks-pnpm-8.15.3/lib/node_modules/.bin/pnpm
nodePackages.pnpm.out                             1,047 x /nix/store/jxyv7qildiy960h194h4ca3wharbbpks-pnpm-8.15.3/lib/node_modules/pnpm/bin/pnpm.cjs
[… other entries unrelated to nodePackages.pnpm …]

As a consequence, the nix-index module fails to propose the right package:

$ pnpm
The program 'pnpm' is currently not installed. It is provided by
several packages. You can install it by typing one of the following:
  nix profile install nixpkgs#corepack_18.out
  nix profile install nixpkgs#corepack.out
  nix profile install nixpkgs#corepack_21.out

Or run it once with:
  nix shell nixpkgs#corepack_18.out -c pnpm ...
  nix shell nixpkgs#corepack.out -c pnpm ...
  nix shell nixpkgs#corepack_21.out -c pnpm ...