-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Search improvements for --file and --expr #7668
base: master
Are you sure you want to change the base?
Conversation
@@ -181,15 +181,21 @@ struct CmdSearch : InstallableCommand, MixJSON | |||
else if (initialRecurse) | |||
recurse(); | |||
|
|||
else if (attrPathS[0] == "legacyPackages" && attrPath.size() > 2) { | |||
else if (file || expr || (attrPathS[0] == "legacyPackages" && attrPath.size() > 2)) |
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.
else if (file || expr || (attrPathS[0] == "legacyPackages" && attrPath.size() > 2)) | |
else if (file || expr || (attrPath.size() > 2)) |
The "legacyPackages" restriction prevents ability to leverage the RecurseForDerivations logic in any other attribute path. This also helps match the behavior a few lines below, also removing the restriction.
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 not sure about flake installables, so I left the behavior as before.
(I think this also matches the behavior of nix flake show
?)
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
This means in commands like "nix search -f '<nixpkgs>'" the input is treated like a 'legacyPackages' package set.
The 'nix search' command uses this function. Without this auto-calling it will fail to find any packages.
87e06dc
to
0c89224
Compare
Triaged in the Nix team meeting: We want to support the use case, and it's relevant for stabilising the new CLI. But the proposed solution is suboptimal. @Ericson2314 and @tomberek will propose an alternative approach and report back. Postponed until then. Complete discussion
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-03-03-nix-team-meeting-minutes-37/25998/1 |
I'd like to clarify that the |
@dramforever would |
A redesign would probably still be nice. In my fork-ish nix-dram I've had it changed to:
Though that's because nix-dram is based on a 'default flake' (see discussion in e.g. #4438), which |
I'm coping with this by using the following alias. Hopefully, that'll help those who, like me, are looking forward to this bug being fixed.
|
I created a wrapper to implement the |
(misclicked, sorry) |
This is a problem to fix to make
"." is better than the empty string, it is still not particularly appealing for general usage. we had said this above, but I'm not clear on a good design yet, see below
The contention is this part of the installables semantics:
brainstorming:
This would require logic for file&&expr to be detected earlier than when the search results are processed. @dramforever this would mean I'd expect conditionals in installable.cc for this case. conclusionthis PR seems to be a step in the right direction, supporting both |
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.
- needs a rebase
- confirmation about what behavior is affected
- Tests look good (though may need more if other behavior is affected, or to detect it)
- release notes
- docs
@@ -505,6 +505,26 @@ struct InstallableAttrPath : InstallableValue | |||
|
|||
return res; | |||
} | |||
|
|||
std::vector<ref<eval_cache::AttrCursor>> getCursors(EvalState &state) override |
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 don't know if the getCursors change will impact other commands, i suspect it would now do an autoCall where before it didn't. It might be desirable to do so, but it is not clear how much behavior this is overriding.
Motivation
The new
nix search
no longer works without flakes without some hacks. This PR fixes this so that this would work:$ nix search --file '<nixpkgs>' '' hello-unfree
Still a slight mouthful, but now it's at least working as much as
--file
could.Context
Discussed in: https://discourse.nixos.org/t/nix-search-broken/24447
A workaround is possible, which uses the special handling of
legacyPackages
to ignore evaluation errors, but it's pretty ugly and relies on a weird internal behavior:$ nix search --impure --expr '{ legacyPackages.${builtins.currentSystem} = import <nixpkgs> {};}' '' hello-unfree
There are two main changes:
CmdSearch
now recurses intorecurseForDerivations = true
iffile || expr
. For better error messages, top-level eval errors are not ignored.InstallableAttrPath::getCursors
now has a custom implementation that auto-calls the value and provides the full attribute path in the cursor (root->findAlongAttrPath
so that is has a correctparent
).Checklist for maintainers
Maintainers: tick if completed or explain if not relevant
tests/**.sh
src/*/tests