-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nix search: Disallow empty regex #9481
nix search: Disallow empty regex #9481
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a strict improvement in my opinion.
outputting the entire output of
nix search --help
when no regex is passed, but that would be a more substantial change
That would be a really cool change though.
Took a while for me to realize that |
9c2dfe9
to
1499e6e
Compare
@roberth Good point! I added a note about this to the description. Also added release notes, this is ready to merge from my side. |
1499e6e
to
e07020a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm coming back to this and the error message is still confusing. I can imagine a user then trying "nix search ^". The key piece of info is that nixpkgs is not the default flake(ahem: dram), and that they need to specify it, assuming that is the most commonly searched flake. That there needs to be more positional arguments.
That's a good point. Ideally, the message would look like this:
But this also has to work for all other kinds of installables (like file and expr), and after trying for over an hour now, I just can't make it happen. The easiest way is to use
Or for files:
I would need some function that returns the installable verbatim, or at least close to verbatim. That would be useful for other error messages as well. Maybe I'll have another crack later. |
e07020a
to
d0231de
Compare
Fixes NixOS#4739 Fixes NixOS#3553 in spirit IMO
d0231de
to
397cf4e
Compare
@tomberek I now settled on this:
I don't know if it's a strict improvement over just Please tell me which variant you like better, and then let's get that merged. Making a function to get the installable verbatim proved to be even more difficult than I thought, and I don't want to block a simple UX improvement like this on a big, possibly controversial addition. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do like the updated message, thx.
Not really in favor of this. |
I guess I should've seen that coming after #4809 was declined. I disagree with "perfectly logical". I would expect a command like I would appreciate concerns like this being raised before a contribution is merged, but whatever. |
My rationale: It is a common problem for an initial user that they will often type "nix search python" and become bewildered. This helps address that by teaching them what they messed up. I agree it is convenient to automatically scan for everything, but the cost of confusion for beginners is too high for the slight benefit. |
I mean I concede it's not a perfect fix. Right now:
With this PR:
I would like it to look more like this
But right now, it's seemingly impossible to get the initial arguments that were passed to a command inside |
## Summary The latest nix version (2.20) changed how the nix profile output is represented: From the [release notes](https://nixos.org/manual/nix/stable/release-notes/rl-2.20): > nix profile now allows referring to elements by human-readable names NixOS/nix#8678 > [nix profile](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-profile) now uses names to refer to installed packages when running [list](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-profile-list), [remove](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-profile-remove) or [upgrade](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-profile-upgrade) as opposed to indices. Profile element names are generated when a package is installed and remain the same until the package is removed. > Warning: The manifest.nix file used to record the contents of profiles has changed. Nix will automatically upgrade profiles to the new version when you modify the profile. After that, the profile can no longer be used by older versions of Nix. and for `nix search`: > Disallow empty search regex in nix search [#9481](NixOS/nix#9481) > [nix search](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-search) now requires a search regex to be passed. To show all packages, use ^. TODOs: - [x] update `nix.readManifest` to handle the new format - [x] `nix search` requires a regex to be passed - [x] manually test on nix < 2.20 on devbox.sh to verify the older nix still works Fixes #1767 ## How was it tested? CICD should pass Installed nix 2.20.1 locally and am using Devbox with it to add, remove packages and run scripts and shell. verified flake updating works: 1. `examples/flakes/remote`. Did `devbox shell`, dropped the `v0.43.1` from process-compose flake, did `devbox update`, and verified that `process-compose` now had the latest version (IIRC `0.80+`) 2. `examples/flakes/php`. Did `devbox shell`, edited the flake to drop `ds` and did `devbox update`. Verified no `ds` in `php -m | grep ds`
…hout-search-terms nix search: Disallow empty regex (cherry picked from commit 1c260fa) Change-Id: Iaaf3605c24a342fcb05d0b534a9f305533d3b5fa
So, I just noticed this now, after happily searching with no regex for a long time. Not all flakes are This "fix" is really an ergonomic regression. At least on my keyboard. |
Ah yes, we talked about that, but concluded that most invocations of
Do you have an example for what the usecase of this is? I tried it on a few of my flakes and it seems to be either useless as it only outputs a single line or errors because it tries to evaluate things that aren't derivations.
This is a very unique situation, and we just can't consider everyone's custom setup. On most keyboards, ^ is a simple two-key combination, either with Shift or Alt Gr. I'm in a similar boat myself as I use a custom keyboard with the US-Intl layout to be able to type german characters easily, and I just added a macro so Shift+6 actually types Shift+6, then space. I think I tried to allow an explicit empty string |
Yes I saw that and agreed.
I use this to explore package groups, like what vim plugins are available, what Ruby gems are packaged for nix etc. When typing
I don't think it's very unique at all. The location might differ (my example above is from a Swedish standard layout, though I used the
Yeah, my workaround that I have yet to internalize is to search for |
Oh, and I also use attribute search to check the version of a package. |
Motivation
This will make invocations of
nix search
without a regex fail with the following error message:This protects users from accidentally printing every package in nixpkgs. If someone still wanted to do that, they can by explicitly passing
^
. Why we recommend this over^
is explained in the docs.Context
Fixes #4739.
Also fixes #3553 in spirit IMO. That issue calls for outputting the entire output of
nix search --help
when no regex is passed, but that would be a more substantial change, as all new CLI commands have no short help and--help
opens the manpage. If we wanted to change that, we should change it for allUsageError
invocations.I considered adding an
--all
flag, but this seemed redundant. I briefly looked into other ways of enforcing at least one argument withexpectArgs
, but addingoptional = false
didn't change the rest of the implementation or the docs, so I opted not to touch that part.Priorities
Add 👍 to pull requests you find important.