NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.78k stars 1.52k forks source link

`nix search` drops version when search term matches package name #2778

Open lilyball opened 5 years ago

lilyball commented 5 years ago

When the nix search search term matches on the package name, the nix search output drops the version from the name. If the term doesn't match on the name but instead matches on the attribute path or description, it displays the version.

For example:

> nix search libgnurl
warning: using cached results; pass '-u' to update the cache
* nixpkgs.libgnurl (libgnurl)
  A fork of libcurl used by GNUnet
> nix search nixpkgs.libgnurl
warning: using cached results; pass '-u' to update the cache
* nixpkgs.libgnurl (libgnurl-7.64.0)
  A fork of libcurl used by GNUnet

I'm assuming this is a consequence of using a different code path when emitting highlighting for the match in the package name.

nix (Nix) 2.2.2

dtzWill commented 5 years ago

..it doesn't show version info? It does here! :/

Hmm: a) I'm seeing version info-- what version of nix are you using? b) #2312 . c) #2658 FWIW.

lilyball commented 5 years ago
 - system: `"x86_64-darwin"`
 - host os: `Darwin 18.5.0, macOS 10.14.4`
 - multi-user?: `no`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.2`
 - channels(eridius): `"nixpkgs-19.09pre175347.02bb5e35eae"`
 - nixpkgs: `/Users/eridius/.nix-defexpr/channels/nixpkgs`

Sample output:

> nix search ffsend
* nixpkgs.ffsend (ffsend)
  Easily and securely share files from the command line. A fully featured Firefox Send client
lilyball commented 5 years ago

The --verbose flag isn't doing anything either:

> nix search --verbose ffsend
* nixpkgs.ffsend (ffsend)
  Easily and securely share files from the command line. A fully featured Firefox Send client
lilyball commented 5 years ago

I figured it out. It omits the version number when the search term matches the package name, but includes it when the search term doesn't match on the package name.

> nix search libgnurl
warning: using cached results; pass '-u' to update the cache
* nixpkgs.libgnurl (libgnurl)
  A fork of libcurl used by GNUnet
> nix search nixpkgs.libgnurl
warning: using cached results; pass '-u' to update the cache
* nixpkgs.libgnurl (libgnurl-7.64.0)
  A fork of libcurl used by GNUnet
lilyball commented 5 years ago

This line is the bug:

wrap("\e[0;2m", hilite(name, nameMatch, "\e[0;2m")),

That should just be

wrap("\e[0;2m", name),

since name already includes the appropriate highlighting. This line is buggy because name includes the version, but nameMatch.suffix() doesn't, so if nameMatch isn't empty then it'll skip the version.

I'm tempted to submit a patch myself but I've never built Nix before. If it's not too hard I might try.

smancill commented 4 years ago

I confirm this is still a problem with nix-2.3.7 in 20.09:

$ nix search neovim-qt
warning: using cached results; pass '-u' to update the cache
* nixpkgs.neovim-qt (neovim-qt)
  Neovim client library and GUI, in Qt5

* unstable.neovim-qt (neovim-qt)
  Neovim client library and GUI, in Qt5

And when matching the full attribute path it does show the version:

$ nix search pkgs.neovim-qt
warning: using cached results; pass '-u' to update the cache
* nixpkgs.neovim-qt (neovim-qt-0.2.15)
  Neovim client library and GUI, in Qt5

Can PR #3055 be considered to fix this? It is quite annoying not being able to see the version for the most common search case of matching the package name.

edolstra commented 4 years ago

I don't think this problem exists anymore on master:

$ nix search nixpkgs neovim-qt
* legacyPackages.x86_64-linux.neovim-qt (0.2.16.1)
  Neovim client library and GUI, in Qt5
lilyball commented 3 years ago

Weird, now it's dropping the name entirely.

https://github.com/NixOS/nix/blob/7a472a76d4dcbbd0eb7832c0bdcb120d32881e8b/src/nix/search.cc#L134-L139

It calculates the name highlight (name2) and then does nothing at all with it. See how @edolstra's output says

* legacyPackages.x86_64-linux.neovim-qt (0.2.16.1)
  Neovim client library and GUI, in Qt5

instead of the expected

* legacyPackages.x86_64-linux.neovim-qt (neovim-qt-0.2.16.1)
  Neovim client library and GUI, in Qt5
edolstra commented 3 years ago

Looks like dead code from when we did show the name.

lilyball commented 3 years ago

Is there a reason we aren't showing name anymore? Especially since it's part of what's being searched. Without showing name, we can end up showing a result with no highlighting because the only match was in the name.

Izorkin commented 3 years ago

The version is still not displayed on some packages:

nix search duf
warning: using cached results; pass '-u' to update the cache
* nixos.duf (duf)
  Disk Usage/Free Utility

* nixos.duff (duff)
  Quickly find duplicate files

* nixos.ocamlPackages.duff (ocaml4.12.0-duff)
  Pure OCaml implementation of libXdiff (Rabin’s fingerprint)

* nixos.python38Packages.dufte (python3.8-dufte)
  Clean matplotlib plots

* nixos.python39Packages.dufte (python3.9-dufte)
  Clean matplotlib plots

* nixpkgs-1903.duff (duff)
  Quickly find duplicate files

* nixpkgs.duf (duf)
  Disk Usage/Free Utility

* nixpkgs.duff (duff)
  Quickly find duplicate files

* nixpkgs.ocamlPackages.duff (ocaml4.12.0-duff)
  Pure OCaml implementation of libXdiff (Rabin’s fingerprint)

* nixpkgs.python38Packages.dufte (python3.8-dufte)
  Clean matplotlib plots

* nixpkgs.python39Packages.dufte (python3.9-dufte)
  Clean matplotlib plots

If add nixpkgs attribute, then the version is displayed:

nix search nixpkgs.duf
warning: using cached results; pass '-u' to update the cache
* nixpkgs.duf (duf-0.6.2)
  Disk Usage/Free Utility

* nixpkgs.duff (duff-2014-07-03)
  Quickly find duplicate files
thufschmitt commented 3 years ago

The version is still not displayed on some packages

It’s working on Nix master:

$ nix search nixpkgs duf
* legacyPackages.x86_64-linux.duf (0.6.2)
  Disk Usage/Free Utility

* legacyPackages.x86_64-linux.duff (2014-07-03)
  Quickly find duplicate files

* legacyPackages.x86_64-linux.ocamlPackages.duff (0.4)
  Pure OCaml implementation of libXdiff (Rabin’s fingerprint)

* legacyPackages.x86_64-linux.python38Packages.dufte (0.2.12)
  Clean matplotlib plots

* legacyPackages.x86_64-linux.python39Packages.dufte (0.2.12)
  Clean matplotlib plots
Izorkin commented 3 years ago

When will these changes be in the stable version?

koiuo commented 3 years ago

came here to report that this is till an issue on nixos-21.05

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

koiuo commented 2 years ago

not stale. Still an issue