Skip to content
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: flake output completion #2374

Closed
Atemu opened this issue May 6, 2024 · 6 comments
Closed

nix: flake output completion #2374

Atemu opened this issue May 6, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@Atemu
Copy link

Atemu commented May 6, 2024

Request

#2350 avoided adding these because fetching these was thought to be too slow (#2348).

This is however quite an essential feature using the nix CLI effectively.

cc @aftix

Proposed solution

Nix has built-in support for completions, couldn't those be leveraged?

NIX_GET_COMPLETIONS=2 nix build nixpkgs# instantly returns a list of completions.

Anything else?

No response

@Atemu Atemu added the enhancement New feature or request label May 6, 2024
@rsteube
Copy link
Member

rsteube commented May 6, 2024

Need to have a look at it, but should have the same issue.
You probably get instant results because you have already invoked it before.

The problem is the first invocation. E.g. there is one nix command that triggers the channel download, which is like ~15mb as far as i remember.
Anything above 100ms starts to feel slow in shell completion. Couple of seconds are fine when it is apparrent to the user that remote data needs to be fetched.
But things like this simply block for quite a long time without any feedback. So it has to be a task detached from the shell completion.
Nothing too complicated, but needs a generic concept as other commands have this issue as well.

@Atemu
Copy link
Author

Atemu commented May 6, 2024

Indeed it has that issue. I pin my nixpkgs, so it is almost always cached for me.

It's honestly not that huge of an issue though IMHO. Better wait a few seconds every so often than to have no completion at all. It's the same with regular upstream bash completions, so, while obviously not ideal, this is intended behaviour.

@aftix
Copy link
Contributor

aftix commented May 6, 2024

With flakes, the time to generate the completions are much faster than using channels, but the first time running the completions command on a flake still takes ~2ish seconds to generate, even if used on a flake located in a local directory.

Atemu added a commit to Atemu/dotfiles that referenced this issue May 17, 2024
It currently cannot complete flake outputs but carapace can be configured to
bridge bash completions for certain commands.

See carapace-sh/carapace-bin#2374
@haennes
Copy link

haennes commented Dec 14, 2024

For the NixOS users looking for solutions: I posted mine here
Before i found out about carapace i just used the default completions for nix. These are blocking for quite some time. In my case sometimes upwards of 20s.
However IMHO it is better have a really slow completion than to have (basically none at all)
As a flake and nixos user, who are usually accustomed to waiting, having tab complete being fast, but actually useless for doing anything with local flakes, I would like it to be blocking.

@rsteube
Copy link
Member

rsteube commented Dec 14, 2024

I don't mind it being a bit slow, so I'm not against adding it.
I just don't want it to randomly download a ~15MB channel without any user feedback.

@aftix
Copy link
Contributor

aftix commented Dec 14, 2024

I did a little more digging. NIX_GET_COMPLETIONS takes a number which is the argument to complete (starting at 0). It is possible to first do something like NIX_GET_COMPLETIONS=2 nix build nixpkgs to check if the flake is in the registry then NIX_GET_COMPLETIONS=2 nix build nixpkgs#<what the user wants to complete> can just return no entries if the flakeref before # isn't already in the registry. So, it is entirely possible to only complete things that are local paths or things that don't need to download from the network. This mechanism also returns a simple list of names for the registry check, so nix does the parsing of nix regististry list to see what's available for us here.

aftix added a commit to aftix/carapace-bin that referenced this issue Dec 14, 2024
Fixes: carapace-sh#2374

This will only complete attributes for flakes that are in
the user's registry or are a local path. This means
that the flake eval cache should be very useful for these
completions, and that carapace won't go out and fetch
random flakes when the user is trying to tab complete.
rsteube pushed a commit that referenced this issue Dec 22, 2024
Fixes: #2374

This will only complete attributes for flakes that are in
the user's registry or are a local path. This means
that the flake eval cache should be very useful for these
completions, and that carapace won't go out and fetch
random flakes when the user is trying to tab complete.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants