NixOS / nix

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

`nix search` should support `-e`/`--exclude` flag #6513

Open lilyball opened 2 years ago

lilyball commented 2 years ago

Is your feature request related to a problem? Please describe. nix search often finds a lot of packages I don't want to see, such as giving me a lot of results in python39Packages.*. I'd like to be able to exclude stuff like that.

Describe the solution you'd like As nix search can take multiple regexes that must all match, I thought it might be nice to support an -e/--exclude flag that takes a single regex arg (and can be specified multiple times) and effectively inverts the regex, requiring that the regex fail to match. This way I can write e.g. nix search nixpkgs tar -e '\.python'.

Describe alternatives you've considered Nix could support something similar to git's pathspec "magic signatures" such that a special prefix denotes exclude. For example, git allows pathspecs to be written like :!foo (or its long form :(exclude)foo). This approach might want to pick some syntax that is normally either a regex syntax error or guaranteed match failure, either that or copy git exactly. This syntax is definitely less obvious than -e but it would allow for a clear path toward things like supporting glob patterns (with git it looks like :(glob)foo*) or specifying particular attributes to search (e.g. :(attr:name)python) which is something I'd also love.

thufschmitt commented 2 years ago

That sounds fair. Think you could implement it?

I’d personally prefer the --exclude version because mixing regex and custom syntax might be very confusing.

(Interestingly, some regexp engines support this natively with the so-called “negative-lookahead”. But not the extended posix one used by nix search)

lilyball commented 2 years ago

I would love to, but I don't have the capacity right now to work on something like this.

I agree that the --exclude version is simpler. Adding something like the alternative "magic signature" syntax can always be done afterwards anyway if desired.

(Interestingly, some regexp engines support this natively with the so-called “negative-lookahead”. But not the extended posix one used by nix search)

Not really. It's certainly possible to write a regex with many engines that looks like ^(?!.*foo), though rather awkward, but even if nix search supported this the fact that it searches multiple attributes of each derivation means that such a regex would only work if every single searched attribute (which IIRC is name, attr path, and description) simultaneously failed that test. This will obviously not work for something like ^(?!.*python3Packages) as neither the name nor description of python modules are going to include the string pythonPackages.

thufschmitt commented 2 years ago

even if nix search supported this the fact that it searches multiple attributes of each derivation means that such a regex would only work if every single searched attribute (which IIRC is name, attr path, and description) simultaneously failed that test

Oh indeed, I’d forgotten about that. So my already moot point is even mooter :)